Author: Tomas Rutkauskas How to create non-selectable separator lines in a TComboBox Answer: Note that the Combobox1.Style is csOwnerDrawvariable. 1 procedure TForm1.FormCreate(Sender: TObject); 2 begin 3 with combobox1 do 4 begin 5 items.add('Item 1'); 6 items.add('Item 2'); 7 items.addObject('Item 3', Pointer(1)); 8 Perform(CB_SetItemHeight, 2, ItemHeight + 5); 9 items.add('Item 4'); 10 items.add('Item 5'); 11 end; 12 end; 13 14 procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer; 15 var Height: Integer); 16 begin 17 Height := (Control as TCombobox).Itemheight; 18 end; 19 20 procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; 21 Rect: TRect; State: TOwnerDrawState); 22 var 23 needsSeparator: Boolean; 24 begin 25 with Control as TCombobox do 26 begin 27 needsSeparator := Assigned(Items.Objects[index]) and not (odComboBoxEdit in 28 State); 29 if needsSeparator then 30 Rect.Bottom := Rect.Bottom - 5; 31 Canvas.FillRect(Rect); 32 Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Items[index]); 33 if needsSeparator then 34 begin 35 Rect.Top := Rect.Bottom; 36 Rect.Bottom := Rect.Bottom + 5; 37 Canvas.Brush.Color := color; 38 Canvas.Pen.Color := font.Color; 39 Canvas.Pen.Style := psSolid; 40 Canvas.Fillrect(Rect); 41 Canvas.MoveTo(rect.left, rect.top + 2); 42 Canvas.LineTo(rect.right, rect.top + 2); 43 end; 44 end; 45 end;