Click here to Skip to main content
Click here to Skip to main content
Go to top

Multi-column Combo

, 6 Apr 2005
Rate this:
Please Sign up or sign in to vote.
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:

    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.:

    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.

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

Share

About the Author

kennedy_franklin
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 Pinmemberhdng7613-Jul-12 7:35 
Questionnice PinmemberCIDev17-Feb-12 2:32 
GeneralFor Dual Column combobox, create the following: Pinmemberwsfaso28-Feb-11 8:55 
GeneralMy vote of 4 PinmemberAnil Dhir20-Oct-10 18:43 
GeneralI am trying to let it work in MS SERVER PinmemberRaghuDhanjal25-Sep-08 3:31 
QuestionIssues with conrols Pinmemberpankajawasthi9911-Feb-07 10:17 
Generalabout the MultiColumn control Pinmembersuditur20-Dec-06 3:58 
Generalembed in datagrid PinmemberHemaRawat28-Dec-05 22:12 
QuestionI have a question? Pinmemberpuvadols12-Oct-05 18:43 
GeneralCombo Box Multi column PinmemberTomKMathew11-Aug-05 18:22 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 6 Apr 2005
Article Copyright 2005 by kennedy_franklin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid