1 (edited by rbknathan 2020-09-14 04:20:45)

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;

2 (edited by CDB 2020-09-14 09:52:10)

Re: Error in Multiselect Combobox

I think you need to change


cb.ItemsChecked[i]



to

cb.ItemIndex[i]

As this will return only the selected items.

On a clear disk you can seek forever

Re: Error in Multiselect Combobox

http://myvisualdatabase.com/forum/viewtopic.php?id=6874