Chris Tribbeck.
"EH" <nos...@hsws.de> a écrit dans le message news:
3D882A7...@hsws.de...
> Hello!
>
> Who knows where i can get a multi-column-combobox?
> Or has anybody programmed such one? (Delphi or C++ source).
>
> Thanx,
> EH :-)
>
> You could make it user-drawn and do the columns yourself. I've got code at
> home, so I won't be able to give you any today. Check the Style property of
> the combo box, press F1 and follow what's written. The appropriate event to
> draw is (IFAICR) is onDrawItem (again, press F1 on that).
Hi Chris,
I know the principals as you described.
For saving time, i don't want to realize it myself, but want to get a
(maybe nearly) complete solution which i then can enhance to fit my further needs.
May be shareware. Perhaps i asked in the wrong newsgroup?
Thank you for your answer,
EH :-)
> Who knows where i can get a multi-column-combobox?
> Or has anybody programmed such one? (Delphi or C++ source).
This would be a strange beast indeed.
If the Combo Box has the Style csSimple (you did not specify), the
ListHandle property will give you the window handle of the List Box.
Otherwise, subclass (or override WndProc) to examine message
WM_CTLCOLORLISTBOX as lParam is the List Box handle.
Having this, you can use this technique to simulate multiple columns with
tabs in a single column list box (essentially copied from previous posting):
AnsiString GetCell(TListBox* ListBox, int Col, int Row)
{
String result = "";
if(Row + 1 > ListBox->Items->Count)
return result;
// create temporary TStringList for columns
TStringList *sl = new TStringList;
// convert tabs to CR/LF so each column is separate Item
sl->Text = StringReplace(ListBox->Items->Strings[Row],
"\t", "\r\n", TReplaceFlags() << rfReplaceAll);
if(sl->Count > Col) result = sl->Strings[Col];
delete sl;
return result;
}
//----------------------------------------------
void SetCell(TListBox* ListBox, int Col, int Row, AnsiString S)
{
// optionally validate input here
while(ListBox->Items->Count < Row + 1)
{
ListBox->Items->Add("");
}
// create temporary TStringList for columns
TStringList *sl = new TStringList;
// convert tabs to CR/LF so each column is separate Item
sl->Text = StringReplace(ListBox->Items->Strings[Row],
"\t", "\r\n", TReplaceFlags() << rfReplaceAll);
// add new lines if necessary
while(sl->Count < Col + 1) sl->Add("");
sl->Strings[Col] = S;
// assemble back to tab delimited string and put into TListBox
ListBox->Items->Strings[Row] = StringReplace(sl->Text, "\r\n",
"\t", TReplaceFlags() << rfReplaceAll);
delete sl;
}
//----------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//randomize();
int row = random(20);
int col = random(6);
String s = String(col) + ", " + row;
SetCell(ListBox1, col, row, s);
}
//----------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
ShowMessage(GetCell(ListBox1, 4, 5));
}
> If the Combo Box has the Style csSimple (you did not specify), the
I want multi-columns for a normal drop-down ComboxBox,
Style = csDropDown or csDropDownList.
> ListHandle property will give you the window handle of the List Box.
> Otherwise, subclass (or override WndProc) to examine message
> WM_CTLCOLORLISTBOX as lParam is the List Box handle.
> Having this, you can use this technique to simulate multiple columns with
> tabs in a single column list box (essentially copied from previous posting)
Unfortunately, i can not follow what you mean. And i'm not sure
whether i can use this technique for the drop-down ComboBox.
When watching the MS Access ComboBox, which supports multi-column ComboBoxes,
i think the solution would be:
- new property: int Columns, i.e. 3
- new property: int EditColumn, i.e. 0 (column no. to be displayed in the Edit box)
- new property: TColor HeaderColor
- new property: AnsiString Headers, i.e. "Name;ZIP;Phone"
- new property: AnsiString ColumnWidths, i.e. "100;30;60"
- as you described the a strings in Items should contain a row
with columns separeted by a separator (may be ";"),
i.e. "Michel;12345;555-123"
- Style must be csOwnerDrawFixed or csOwnerDrawVariable.
Using the events OnDrawItem and OnMeasureItem to draw the ComboBox.
Nice to have: a new property editor for the Items.
You see, this is not so easy to implement.
I'm sure there will be many open questions, when realizing such
a component.
I found no multi-column-combobox VCL-component at all over the internet...
Thank you,
EH :-)
> Unfortunately, i can not follow what you mean. And i'm not sure
> whether i can use this technique for the drop-down ComboBox.
The technique for getting the List Box handle allows you to send API
messages to the List Box. The technique I showed would need to be
implemented using these messages. Check win32.hlp for "List Box
Messages."
> When watching the MS Access ComboBox, which supports
> multi-column ComboBoxes, i think the solution would be:
> - new property: int Columns, i.e. 3
> - new property: int EditColumn, i.e. 0 (column no. to be displayed in the Edit box)
> - new property: TColor HeaderColor
> - new property: AnsiString Headers, i.e. "Name;ZIP;Phone"
> - new property: AnsiString ColumnWidths, i.e. "100;30;60"
> - as you described the a strings in Items should contain a row
> with columns separeted by a separator (may be ";"),
> i.e. "Michel;12345;555-123"
> - Style must be csOwnerDrawFixed or csOwnerDrawVariable.
I'm not familiar with the Access ComboBox, and I don't have it installed
at the moment. The standard Windows Combo Box, when in multi-
column mode, has columns whose items are not related, but instead
of having a vertical scroll-bar, the items wrap to the next column. That
doesn't seem to be what you want when you say "multicolumn."
> You see, this is not so easy to implement.
> I'm sure there will be many open questions, when realizing such
> a component.
> I found no multi-column-combobox VCL-component at all over the internet...
Maybe you could just use separate controls to "look like" a Combo Box.
You could use a TEdit, a TSpeedButton, and drop-down a TListView in
vsReport mode, or use the TListBox as I have shown. You might even be
able to use a TListBox and employ the Items::CommaText property to
load. A lot depends on exactly how you were loading it, i.e., at design
time or runtime, and how often you needed to make changes. Check out
the May 2001 article named "Custom popup controls" in the C++ Builder
Developers Journal at:
http://www.bridgespublishing.com/articles/articleindex.htm
Ok. I'll check it.
> I'm not familiar with the Access ComboBox, and I don't have it installed
> at the moment. The standard Windows Combo Box, when in multi-
> column mode, has columns whose items are not related, but instead
> of having a vertical scroll-bar, the items wrap to the next column. That
> doesn't seem to be what you want when you say "multicolumn."
Right.
> Maybe you could just use separate controls to "look like" a Combo Box.
> You could use a TEdit, a TSpeedButton, and drop-down a TListView in
> vsReport mode, or use the TListBox as I have shown. You might even be
> able to use a TListBox and employ the Items::CommaText property to
> load. A lot depends on exactly how you were loading it, i.e., at design
> time or runtime, and how often you needed to make changes. Check out
> the May 2001 article named "Custom popup controls" in the C++ Builder
> Developers Journal at:
> http://www.bridgespublishing.com/articles/articleindex.htm
Ah, this looks very interesting.
Thank you for your tips,
EH :-)