Re:more questions, on creating a combobox with list boxes
In article <3ba6872...@corp.newsgroups.com>, "Gino Costa" <gco...@beld.net>
writes:
Quote
>I have another question.
>I want to create something like a scrollable combobox or listbox where each
>string entry is also accompanied by a small combobox of it's own. This would
>be sort of like a tCheckListBox component but instead of a check box, I want
>a small combobox for each entry.
>What I need this is to manage strings, and I want each string to have a
>designation between A and F, and to let the user select the designation (vis
>the small combo box) (but not change the strings themselves).
Put a listbox and a combobox (with style set to csDropDownList). Fill the
combobox with the list of options and the listbox with those selected. Then
code as follows ...
procedure TForm1.ListBox1Click(Sender: TObject);
begin
{position and drop-down the combobox}
with ListBox1 do begin
ComboBox1.SetBounds(Left,
Top + ((ItemIndex - TopIndex) * ItemHeight) - 2,
Width,
ComboBox1.Height);
{select existing listbox option in combobox}
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(Items[ItemIndex]);
ComboBox1.Text := ComboBox1.Items[ComboBox1.ItemIndex];
ComboBox1.Visible := true;
ComboBox1.Perform(CB_SHOWDROPDOWN, 1, 0);
ComboBox1.SetFocus;
end;
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
{transfer the selected item into the listbox}
with ListBox1 do
Items[ItemIndex] := ComboBox1.Items[ComboBox1.ItemIndex];
ComboBox1.Visible := false;
end;
procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
{close combobox}
if Key = VK_ESCAPE then
ComboBox1.Visible := false;
end;
Alan Lloyd
alangll...@aol.com