Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

OnDrawItem event of TLMDListBox

edited February 2014 in LMD-Tools Vote Up0Vote Down
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

  • 4 Comments sorted by Votes Date Added
  • I strongly recommend that you review the source code of 

    procedure TLMDListBox.DrawItem(

    to learn how to create your own drawing routine (the code above does neglect many things, not only the separation of columns).
    To change color of lines, there are much simpler ways, though. Check
    OnPrepareDrawItem event or even simpler
    OnGetLineSettings  (here you can specify line color and font settings only)
  • I am using LMD 6 which doesn't appear to have OnGetLineSettings.

    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).

Sign In or Register to comment.