Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to draw multiple columns in a TComboBox Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
114
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to draw multiple columns in a TComboBox

Answer:

You can go with a custom drawn combo box:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
7     Forms, Dialogs, StdCtrls, ExtCtrls;
8   
9   type
10  
11    TDataRec = class(TObject)
12    private
13      Str1: string;
14      Str2: string;
15    end;
16  
17    TForm1 = class(TForm)
18      DeleteListBox1: TListBox;
19      Header1: THeader;
20      Image1: TImage;
21      ComboBox1: TComboBox;
22      procedure FormCreate(Sender: TObject);
23      procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
24        State: TOwnerDrawState);
25    private
26      { Private declarations }
27    public
28      { Public declarations }
29    end;
30  
31  var
32    Form1: TForm1;
33  
34  implementation
35  
36  {$R *.DFM}
37  
38  procedure TForm1.FormCreate(Sender: TObject);
39  var
40    i: integer;
41    DataRec: TDataRec;
42  begin
43    for i := 1 to 10 do
44    begin
45      DataRec := TDataRec.Create;
46      with DataRec do
47      begin
48        Str1 := 'String1 ' + IntToStr(i);
49        Str2 := 'String2 ' + IntToStr(i);
50      end;
51      ComboBox1.Items.AddObject('', DataRec);
52    end;
53  end;
54  
55  procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: 
56  TRect;
57    State: TOwnerDrawState);
58  var
59    S1, S2: string;
60    TempRect: TRect;
61  begin
62    S1 := TDataRec(ComboBox1.Items.Objects[Index]).Str1;
63    S2 := TDataRec(ComboBox1.Items.Objects[Index]).Str2;
64    ComboBox1.Canvas.FillRect(Rect);
65    TempRect := Rect;
66    TempRect.Right := Header1.SectionWidth[0];
67    ComboBox1.Canvas.StretchDraw(TempRect, Image1.Picture.Graphic);
68    Rect.Left := Rect.Left + 50;
69    DrawText(ComboBox1.Canvas.Handle, PChar(S1), Length(S1), Rect, dt_Left or 
70  dt_VCenter);
71    Rect.Left := Rect.Left + 100;
72    DrawText(ComboBox1.Canvas.Handle, PChar(S1), Length(S1), Rect, dt_Left or 
73  dt_VCenter);
74  end;
75  
76  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC