keats88
asked on
Delphi combobox Clear; creates blank fillers
with stdCalc do
begin
Clear;
Items.add('n = None');
if (mbm.mbmid <> '') AND (prt.basetype='F') then
begin
if portLen > 1 then
Items.add('1 = 1 Year');
end;
end;
The Clear; function deletes everything and creates a blank item and then adds the other items below the blank item.
How can I modify this to not have the box area fill in blank?
Thanks,
what do you like inside the box ?
Hi my friend,
if you want to have the selected Item,
you can get it before clear and than after clear add it again. for example
.....
s:= text;
Clear;
Items.Add(s)
......
maybe i cant understand your mean, if so please explain mor clear.
Best regards
if you want to have the selected Item,
you can get it before clear and than after clear add it again. for example
.....
s:= text;
Clear;
Items.Add(s)
......
maybe i cant understand your mean, if so please explain mor clear.
Best regards
draw the combox box black :
see code below :
You need to set the property Style to "csOwnerDrawFixed".
This causes a call of OnDrawItem for each item in your combobox.
see code below :
You need to set the property Style to "csOwnerDrawFixed".
This causes a call of OnDrawItem for each item in your combobox.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
combobox1.items.Add(IntToStr(combobox1.Items.Count));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
combobox1.items.Clear;
combobox1.text := 'NEW';
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with Control as TComboBox,Canvas do
begin
// fill the rectangle first with white
Brush.Color := clBlack;
FillRect(Rect);
// then reduce it and fill it with the color
InflateRect(Rect,-2,-2);
Brush.Color := StrToInt(Items[Index]);
FillRect(Rect);
end;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
These worked perfectly. Thanks!