Is it possible to show multiple columns when you use a tcombobox? If so, can some additional details be provided?

Comments

  1. For a combo box, set Style to csOwnerDrawFixed, and add code like this to the OnDrawItem event:

    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
    Rect: TRect; State: TOwnerDrawState);
    const
    AdditionalInfo: array[0..5] of string =
    ('One', 'Two', 'Three', 'Four', 'Five', 'Six');
    var
    s: string;
    begin
    // Calculate new data to display here
    s := ComboBox1.Items[Index] + ': ' + AdditionalInfo[Index];
    // Clear the display rect and write the new string to it.
    ComboBox1.Canvas.FillRect(Rect);
    ComboBox1.Canvas.TextOut(Rect.Left + 2, Rect.Top, s);
    end;

    Note that this will not produce "columns" - you'll be responsible for spacing. You can do it with multiple calls to TextOut, one for each column.

    ReplyDelete

Post a Comment