I would suggest creating a ComboBox drawing for this. Set the csOwnerDrawFixed
property to csOwnerDrawFixed
, then save only the numbers '1'
, '2'
, '3'
, etc. In the TComboBox.Items
property and use the TComboBox.OnDrawItem
event to display full lines when you see a drop-down list, for example:
var sTheSelectedValue : string; const ItemStrings: array[0..7] of string = ( '0 to 0.1 Calm (rippled)', '0.1 to 0.5 Smooth (wavelets)', '0.5 to 1.25 Slight', '1.25 to 2.5 Moderate', '2.5 to 4 Rough', '4 to 6 Very rough', '6 to 9 High', '9 to 14 Very high'); procedure TForm1.FormCreate(Sender: TObject); var I: Integer; begin ComboBox1.Items.BeginUpdate; try for I := Low(ItemStrings) to High(ItemStrings) do begin ComboBox1.Items.Add(IntToStr(I+1)); end; finally ComboBox1.Items.EndUpdate; end; end; procedure TForm1.ComboBox1Select(Sender: TObject); begin sTheSelectedValue := IntToStr(ComboBox1.ItemIndex+1); Button1.Caption := sTheSelectedValue; end; procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var s: String; begin if odSelected in State then begin ComboBox1.Canvas.Brush.Color := clHighlight; ComboBox1.Canvas.Font.Color := clHighlightText; end else begin ComboBox1.Canvas.Brush.Color := ComboBox1.Color; ComboBox1.Canvas.Font.Color := ComboBox1.Font.Color; end; ComboBox1.Canvas.FillRect(Rect); s := IntToStr(Index+1); if not (odComboBoxEdit in State) then begin s := s + ' ' + ItemStrings[Index]; end; ComboBox1.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, s); if (State * [odFocused, odNoFocusRect]) = [odFocused] then begin ComboBox1.Canvas.DrawFocusRect(Rect); end; end;
source share