Topic: Error in Multiselect Combobox
I am using below code to get the selected Items It works fine in case of single select combo box and also for individual selections in multiselect combobox. But not working fine with using Select All option in the multi select Combo Box. Any suggestions ?
function getComboBoxSelections(cb : TdbComboBox) : Variant;
var
i, counter : integer = 0;
arr : array of string;
begin
SetLength(arr, cb.SelectedCount);
if cb.SelectedCount > 0 then
begin
for i := 0 to cb.Items.Count-1 do
begin
if cb.ItemsChecked[i] then
begin
arr[counter] := cb.Items[i];
Inc(counter);
end;
end;
end;
result := arr;
end;
procedure frmMain_OnShow (Sender: TObject; Action: string);
begin
frmMain.ComboBox1.MultiSelect := True;
frmMain.ComboBox1.Items.Add('All');
frmMain.ComboBox1.Items.Add('a');
frmMain.ComboBox1.Items.Add('b');
end;
procedure frmMain_ComboBox1_OnChange (Sender: TObject);
var
v:variant;
begin
v := getComboBoxSelections(frmMain.ComboBox1);
end;