Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Listview con flechas (https://www.clubdelphi.com/foros/showthread.php?t=92750)

Angel.Matilla 19-01-2018 14:04:01

Listview con flechas
 
Estaba usando un código que escafandra puso en otro foro para pintar flechas de ordenamiento en un TListView; el código es este:
Código:

int LastSortedColumn;
bool Ascending;

void SetSortIcon(TListView *ListView, int ColumnIndex, BOOL Orden)
{
    HANDLE hHeader;
    HD_ITEM HD;

    hHeader = (HANDLE)SendMessage(ListView->Handle, LVM_GETHEADER, 0, 0);
    for (int i = 0; i < ListView->Columns->Count; i++)
    {
          HD.mask = HDI_FORMAT;
          SendMessage(hHeader, HDM_GETITEM, i, DWORD(&HD));
          if (i == ColumnIndex)
          {
              if (Orden)
                    HD.fmt = (HD.fmt & ~HDF_SORTUP) | HDF_SORTDOWN;
              else
                    HD.fmt = (HD.fmt & ~HDF_SORTDOWN) | HDF_SORTUP;
          }
          else
              HD.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);

          SendMessage(hHeader, HDM_SETITEM, i, DWORD(&HD));
    }
}
//---------------------------------------------------------------------------

int  __stdcall SortByColumn(long Item1, long Item2, long Data)
{
    int w;
    TListItem* item1 = reinterpret_cast<TListItem*>(Item1);
    TListItem* item2 = reinterpret_cast<TListItem*>(Item2);

    switch (item1->ListView->Column[Data]->Tag)
    {
          case 0:  // Texto
              if (Data == 0)
                    w = AnsiCompareText(item1->Caption, item2->Caption);
              else
                    w = AnsiCompareText(item1->SubItems->Strings[Data - 1], item2->SubItems->Strings[Data - 1]);
              break;
          case 1:  // Numérico
              if (Data == 0)
                    w = item1->Caption.ToIntDef(0) - item2->Caption.ToIntDef(0);
              else
                    w = item1->SubItems->Strings[Data - 1].ToIntDef(0) - item2->SubItems->Strings[Data - 1].ToIntDef(0);
              break;
          case 2:  // Fecha
              if (Data == 0)
                    w = StrToDateDef(item1->Caption, dFechaNula) - StrToDateDef(item2->Caption, dFechaNula);
              else
                    w = StrToDateDef(item1->SubItems->Strings[Data - 1], dFechaNula) - StrToDateDef(item2->SubItems->Strings[Data - 1], dFechaNula);
              break;
    }
    return Ascending ? w : -w;
}
//---------------------------------------------------------------------------

void __fastcall TfPersona::LisRecColumnClick(TObject *Sender, TListColumn *Column)
{
    if (Column->Index == LastSortedColumn)
          Ascending = !Ascending;
    else
    {
          Ascending = true;
          LastSortedColumn = Column->Index;
    }

    SetSortIcon(LisRec, Column->Index, Ascending);
    static_cast<TListView *>(Sender)->CustomSort(SortByColumn, Column->Index);
}
//---------------------------------------------------------------------------

Funciona a la perfección, pero el aspecto del ListView no me convence porque la flecha se coloca en la parte superior de la columna y es poco visible.

¿Cómo habría que modificar el código para que se pintara, como suele ser habitual, en el lado derecho de la columna?

Ñuño Martínez 22-01-2018 11:46:21

Qué raro. Tenía entendido que de esa "flecha" se encarga de dibujarla el gestor de ventanas. ¿No será por la configuración? Aunque no me suena que esté en ningún sitio...

Angel.Matilla 22-01-2018 19:59:24

Yo la configuración, ni de Windows ni de BCB, las he tocado.

escafandra 26-01-2018 23:47:45

El código que comentas se basa en dejar que el gestor de ventanas de Windows pinte la flechita y la pinte en el centro de la columna arriba del texto. Esto es así en con los estilos XP MANIFEST.

Si quieres personalizar la flechita tienes que dibujarla tu mismo, este hilo comienza de esa manera.


Saludos.


La franja horaria es GMT +2. Ahora son las 03:48:18.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi