{Para testar, insira um TCcomboBox no form, declare a variavel abaixo:}
... private
Selected: arrayof Boolean;
... {E coloque as funções abaixo nos eventos OnDrawItem e OnSelect do combobox}
//Desenha combo procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState); begin
SetLength(Selected, TComboBox(Control).Items.Count); with TComboBox(Control).Canvas do begin
FillRect(rect);
ifnot (odSelected in State) and (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT) elseif (odFocused in State) and (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT) elseif (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT) elseifnot (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_FLAT);
procedure TForm1.ComboBox1Select(Sender: TObject); var
i: Integer;
Sel: string; begin
Sel := EmptyStr;
Selected[TComboBox(Sender).ItemIndex] := not Selected[TComboBox(Sender).ItemIndex]; for i := 0 to TComboBox(Sender).Items.Count - 1 do if Selected[i] then
Sel := Sel + TComboBox(Sender).Items[i] + ' ';
ShowMessage(Sel); //Mostra mensagem com todos os itens marcados (para testar) end;
procedure TForm1.FormCreate(Sender: TObject); begin
ComboBox1.Items.Add('Felipe');
ComboBox1.Items.Add('Monteiro');
ComboBox1.Items.Add('Teste'); end;