This forum is temporaily read-only. All existing discussions remain available for reference. For new questions, bug reports or support requests, please contact us at mail@lmdsupport.com.

Using OwnerDraw in TElXTree

Hi,

I want to define style myself for certain cells. This is my code:

void TForm1::Inital()
{
ElXTree1->Items->BeginUpdate();
for(int i=0; i<ElXTree1->Items->Count; i++)
{
ElXTree1->Items->Item[i]->Cells->Cell[3]->UseOwnStyle = true;
ElXTree1->Items->Item[i]->Cells->Cell[3]->Style->DrawStyle = elhsOwnerDraw;
}
ElXTree1->Items->EndUpdate();
}

And I use OnCellDraw Event:

void __fastcall TForm1::ElXTree1CellDraw(TObject *ASender, TElXTreeCell *ACell, TCanvas *ACanvas, TRect &R)
{
if(ACell->HeaderSection->Index == 3)
{
ACanvas->Brush->Color = clYellow;
ACanvas->Font->Color = clRed;
}

ACanvas->TextRect(R, R.left, R.top, L"Test");
}

Generally, the Tree can be drawn normally, but When I set the style, the TextRect will be abnormal.

imageimage

Is there any suggestions?

Comments

  • I'll look. But, generally, you can specify all colors manually (for ACell->HeaderSection->Index != 3 case)
  • Thanks for your suggestion. My program needs to handle this field, so I use this way.
  • I've checked it. You can use Canvas.Refresh as a quick workaround for now:

    procedure TForm3.ElXTree1CellDraw(ASender: TObject; ACell: TElXTreeCell;
      ACanvas: TCanvas; R: TRect);
    begin
      if ACell.HeaderSection.Index = 3 then
      begin
        ACanvas.Refresh;

        ACanvas.Brush.Color := clYellow;
        ACanvas.Font.Color  := clRed;

        ACanvas.TextRect(R, R.left, R.Top, 'Test');
      end;
    end;
Sign In or Register to comment.