Click here to Skip to main content
15,885,244 members
Articles / Desktop Programming / Windows Forms
Article

Multi-column Combo

Rate me:
Please Sign up or sign in to vote.
4.26/5 (26 votes)
6 Apr 20052 min read 118.5K   2.3K   49   17
A multi-column combo in VB.NET.

Introduction

This is a simple multi-column combo having the facility to load data from a table, and sort the data in the combo by clicking the column header. In this UserControl, I have used Windows Forms controls (ComboBox and ListView) and a few lines of coding.

The properties and methods in this User Control are as follows:

Properties

  • ColumnSize

    Used to specify the column size of the combo.

  • ColumnTitle

    To specify the column title of the combo.

  • DataFieldList

    Used to store the data of a selected item.

    Example: in the demo combo, there are two columns, EmployeeCode and Name. When we select an item from the combo list, we want to store the employee code in the database and the name has to be displayed as a text in the control. This property is used to keep the employee code.

  • DataFieldToDisplay

    The item of the column to display in the control, after selection.

  • DataSource

    If we want to load the data from the database, we can make use of this property.

    Example:

    VB
    Dim CnStr As String
    Dim Appcn As New System.Data.OleDb.OleDbConnection()
    Dim Da As New System.Data.OleDb.OleDbDataAdapter()
    Dim Ds As DataSet
    CnStr = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\Data\Employee.MDB"
    Appcn = New System.Data.OleDb.OleDbConnection(CnStr)
    Appcn.Open()
    Da = New System.Data.OleDb.OleDbDataAdapter("Select * From Employee", Appcn)
    Ds = New DataSet("Combo")
    Da.Fill(Ds, "Combo")
    MulCol.DataSource = Ds.Tables("Combo")
  • ItemsToDisplay

    If we need to add some items to the combo not from the database, we can make use of this property. It’s a design time property. If we need more than one column, we have to separate them by comma (,). Example:

    RAC001,RACHID

    In the above example, ‘RAC001’ is an employee code and RACHID is the employee name. So in the combo, it will come as two columns.

  • RowsToDisplay

    This is to specify how many rows are to be displayed in the drop down.

  • Text

    In this property, the selected item will be stores.

  • Value

    This property will store the value of ‘DataFieldList’.

Method

  • AddItem

    This method is used to add items in the combo at run time. The columns have to be separated by comma (,). E.g.:

    VB
    MulCol.AddItem("RAC001,RACHID")

Property Page

How to use this control

Add this control into the project. Set the properties as mentioned above, in the property sheet. Place the following code in the form load event handler.

VB
MulCol.LoadData() '---- This is the code to load the combo

Assume that the UserControl name is ‘MulCol’.

Note: If you are not going to load the data from the table, then don’t forget to add the data in the ‘ItemsToDisplay’ property. If you need to add more than one column, then separate the first item and the following items by a comma (,).

For more details, you can see the demo application. It’s a self explanatory one. And the user control also is a self explanatory one. And wherever comments are needed, I have placed the required comments too.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Kuwait Kuwait
I am J. Franklin Kennedy, Working as a programmer in application software developement.


Comments and Discussions

 
QuestionNot able to download the source code or demo for Multi-column combo Pin
hdng7613-Jul-12 7:35
hdng7613-Jul-12 7:35 
Questionnice Pin
BillW3317-Feb-12 2:32
professionalBillW3317-Feb-12 2:32 
GeneralFor Dual Column combobox, create the following: Pin
wsfaso28-Feb-11 8:55
wsfaso28-Feb-11 8:55 
GeneralMy vote of 4 Pin
akd0120-Oct-10 18:43
akd0120-Oct-10 18:43 
GeneralI am trying to let it work in MS SERVER Pin
RaghuDhanjal25-Sep-08 3:31
RaghuDhanjal25-Sep-08 3:31 
QuestionIssues with conrols Pin
pankajawasthi9911-Feb-07 10:17
pankajawasthi9911-Feb-07 10:17 
Generalabout the MultiColumn control Pin
suditur20-Dec-06 3:58
suditur20-Dec-06 3:58 
Generalembed in datagrid Pin
HemaRawat28-Dec-05 22:12
HemaRawat28-Dec-05 22:12 
QuestionI have a question? Pin
puvadols12-Oct-05 18:43
puvadols12-Oct-05 18:43 
GeneralCombo Box Multi column Pin
TomKMathew11-Aug-05 18:22
TomKMathew11-Aug-05 18:22 
GeneralQn for Progress Bar Pin
TomKMathew11-Aug-05 18:17
TomKMathew11-Aug-05 18:17 
Questionlimited by form borders? Pin
quick_dry9-Aug-05 18:43
quick_dry9-Aug-05 18:43 
GeneralSetting Selection Pin
Member 202974613-Jun-05 6:53
Member 202974613-Jun-05 6:53 
QuestionCan i use this control in .net compact framework Pin
MaLong99826-May-05 5:38
MaLong99826-May-05 5:38 
Wonder if i can apply this control to the .NET CF, for example Windows CE platform. Thanks
GeneralDismiss droplist Pin
Brian Schallhammer26-May-05 3:59
sussBrian Schallhammer26-May-05 3:59 
GeneralOwner Drawn Columns Pin
Tom John5-May-05 7:25
Tom John5-May-05 7:25 
QuestionEscape? Pin
ChefGroovy18-Apr-05 1:03
ChefGroovy18-Apr-05 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.