ListView farbig kann nichts finden



  • Hallo, ich suche schon wie ein idiot doch leider stimmt etwas mit der suchfunktion noch nicht. Ich will meine ListViewItems farbig habe. Ich habe natürlich schon ein paar sachen aus der FAQ gelernt doch leider habe ich ein problem. Mein ListView wird nicht komplett gezeichnet nur Caption. Hier ist mein Code:

    void __fastcall TFormLagerbestand::ListView1DrawItem(
          TCustomListView *Sender, TListItem *Item, TRect &Rect,
          TOwnerDrawState State)
    {
        if(State.Contains(odSelected))
        {
             ListView1->Canvas->Brush->Color = clWhite;   // Hintergrundfarbe
             ListView1->Canvas->Font->Color = clRed;  // Textfarbe
        }
        else
        {
              ListBox1->Canvas->Brush->Color = clWhite; // dito
              ListBox1->Canvas->Font->Color = clRed;
        }
         //Hintergrund zeichnen
            ListView1->Canvas->FillRect(Rect);
        // Text zeichnen
    
        ListView1->Canvas->TextRect(Rect, Rect.Left, Rect.Top,ListView1->Items-          >Item[i]->SubItems->Strings[0] );  !!!!!!!!!!!!!!!
         }
    
        if(State.Contains(odFocused))
        ListView1->Canvas->DrawFocusRect(Rect);
    }
    

    natürilch ist das zu 99,99% der selbst code wie in der FAQ. Nur ich brauche es halt für ListView und nicht ListBox. Da wo ich !!!!!-Zeichen gemacht habe, denke wird es dran liegen nur ich weiß nicht wie ich das schreiben soll dass mir komplette die ganzen zeile angezeigt werden und nicht nur eine spalte. Kann mir vieleicht jemand helfen?

    danke

    Edit:
    Bitte die Code-Tags benutzen. Danke!



  • Hi
    versuch's mal damit:

    ListView1CustomDrawItem(TCustomListView *Sender, TListItem *Item, TCustomDrawState State, bool &DefaultDraw) {
        AnsiString chStr = "";
        if (Item->SubItems->Count >= 9) {
            chStr = Item->SubItems->Strings[8];
        }
        if (chStr == "." ) {//steuert bei mir ob das farbig sein soll!!!
            ListView1->Canvas->Brush->Color = StringToColor("0x00CCFFEB");
            ListView1->Canvas->Font->Color = clBlack;
        } else {
            ListView1->Canvas->Font->Color = clLtGray;
        }
        AnsiString text = Item->Caption;
        Canvas->TextRect(Item->DisplayRect(drBounds), Item->DisplayRect(drBounds).Left, Item->DisplayRect(drBounds).Top, text);
    


  • hi,

    versuch es mal so:

    void __fastcall TForm1::ListViewCustomDrawItem(TCustomListView *Sender,
          TListItem *Item, TCustomDrawState State, bool &DefaultDraw)
    {
    
       TColor BgCol;
       TColor PenCol;
       PenCol = clBlack;
    
       switch(intwert)
       {
          case '0':
          {
             BgCol = clRed;
             PenCol = clBlack;
             break;
          }
          case '1':
          {
             BgCol = clYellow;
             PenCol = clBlue;
             break;
          }
          default:
          {
             DefaultDraw = true;
             return;
          }
       }
    
       Sender->Canvas->Brush->Color = BgCol;
       Sender->Canvas->Font->Color = PenCol;
    }
    //---------------------------------------------------------------------------
    

    Hoff es hilft dir weiter

    Grüßle


Anmelden zum Antworten