I'm using a TLMDListBox where I want certain items to have a different background color. The list box has columns so I'm populating it using statements like:
lstTableFields.AddLine(['Invoice Date', 'INVCDATE']);
I set the style to OwnerDrawFixed and use the code below to set the background color. The color is set correctly but it is displaying the text for both columns, with the semicolon delimiter, in the first column, like this:
Invoice Date;INVCDATE
procedure TformReceipt.lstTableFieldsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
with lstTableFields.Canvas do begin
if (Index=3) or (Index=5) then
Brush.Color := clRed
else
Brush.Color := clWhite;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top, lstTableFields.Items[index]);
end;
end;
How can I get this to work so the columns are separated correctly when using owner draw on this control?
Comments
I'm finding the drawing code to be difficult to understand so can you provide some sample code to do this? Thanks very much.
>>I am using LMD 6 which doesn't appear to have OnGetLineSettings.<<
ok, then this is a perfect reason to update - changing font Settings and line colors is really simple.
>>I'm finding the drawing code to be difficult to understand so can you provide some sample code to do this?<<
Sorry, but what part is difficult to understand?
As you can see it is not possible to create an own drawing handler with three or 4 lines (therefore additional Events were added in later releases to simplify things). You have to understand this code to write your own custom handler (Splitting strings and observe the boundaries of each column - all code is there).