Mega Code Archive

 
Categories / Delphi / Examples
 

Comboboxmulticolumn

> Hi all, > > Does anyone know of a (freeware preferable) combo box that can support > multiple columns? I'm not sure if such an animal exists, but I have a > client who wants to be able to select a fault from a standard drop > down combo list of them, as well as a priority for that fault, listed > in a separate column so that it looks like: > John, You could use a regular combo box and set the OwnerDraw property to true. On the OnDrawItem event parse out the contents of the item and draw it in two columns. I do this all the time, for an example within a combo box I display the city and postal code for a given location in two columns. Eg. procedure TLocDetForm.SelectedLocationsBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Ctrl: TComboBox; iCol2: integer; begin iCol2:=45; // or whatever you want column 2 to start at Ctrl:=(Control as TComboBox); with Ctrl.Canvas do begin TextRect(Rect,4,Rect.Top,GetField(#9,Ctrl.Items[Index],1)); Rect.Left:=Rect.Left+iCol2; TextRect(Rect,Rect.Left,Rect.Top,GetField(#9,Ctrl.Items[Index],2)); end; end; The function GetField() above parses out the tab delimeted combo box item and returns a string corresponding to the given field number.