ARTICLE

MultiColumn ComboBox with Configurable Display and Value Members and Fast Search functionality

Posted by Vijay Kankhare Articles | Windows Forms C# January 20, 2011
After searching for a MultiColumn ComboBox with configurable view columns, configurable display & value members, I decided to create my own control.
Reader Level:
Download Files:
 


Introduction

After searching for a MultiColumn ComboBox with configurable view columns, configurable display & value members, I decided to create my own control.

The Multi-Column ComboBox is a combination of TextBox, Button & DataGridView control. Since I had a need to create a control like a ComboBox and with search functionality, I decided to use DataGridView & it's filter criteria for fast search functionality.

One of the harder things to figure out was what container to show on key press of the combo control. I used ToolStripDropDown as a host control for DataGridView to show the ComboBox popup on key press.

multi.gif

Common Properties:

  1. Show Header: Set column header visibility.
  2. Grid Lines: Set grid lines as None, Vertical, Horizontal or Both.
  3. DropDown Height: Configurable dropdown height. It will show scrollbar if more items present.
  4. DataSource: DataSource will be a DataTable.
  5. SourceDataString: Mapping Properties which will be shown as Columns.
  6. SourceDataHeader: Column Headers which will be shown if Show Header property is true.
  7. ColumnWidth: Width for each column.
  8. Display Column No: Column number which will be work as a DisplayMember.
  9. Value Column No: Column number which will be work as a ValueMember.

Usage

The Control usage is very simple & straight forward. Set the following properties to configure the control:

private void InitializeComboBox()
{
    multiColumComboBox1.Clear();
    multiColumComboBox1.SourceDataString = new string[3] { "ID", "Name", "Code" };          
    multiColumComboBox1.ColumnWidth = new string[3] { "0", "200", "50" };        
    multiColumComboBox1.DataSource = GetDataSource();          
}

private DataTable GetDataSource()
{
    DataTable dtSource = new DataTable();
    DataColumn dtColID = new DataColumn("ID");
    dtColID.DataType = System.Type.GetType("System.String");
    dtSource.Columns.Add(dtColID);

    DataColumn dtColName = new DataColumn("Name");
    dtColName.DataType = System.Type.GetType("System.String");
    dtSource.Columns.Add(dtColName);

    DataColumn dtColCode = new DataColumn("Code");
    dtColCode.DataType = System.Type.GetType("System.String");
    dtSource.Columns.Add(dtColCode);

    //Add rows
    DataRow row = dtSource.NewRow();          
    row[dtColID] = "1";
    row[dtColName] = "Vijay";
    row[dtColCode] = "1001";
    dtSource.Rows.Add(row);

    //Add rows
    row = dtSource.NewRow();
    row[dtColID] = "2";
    row[dtColName] = "Ajay";
    row[dtColCode] = "1002";
    dtSource.Rows.Add(row);

    . . . . .
    . . . . .

    return dtSource;
}

 

Login to add your contents and source code to this article
post comment
     

hi.... George's problem is same as my problem.. But I found the solution for this.U just need to add code for the popup in Deactivate event at the time of initialization. just like this.private popup_Deactivated(object sender,EventEargs e) {//You just need to close popup here... } enjoyyyyyyyyyyyyyyyy......:)

Posted by sunil kumar May 30, 2012

Hi, good work but i found a small problem.popup is not closing if we click on the form.so popup control is still showing the original location.can you guide me to solve this problem.

Posted by George Garvasis May 05, 2012

Hi, good work but i found a small problem.popup is not closing if we click on the form.so popup control is still showing the original location.can you guide me to solve this problem.

Posted by George Garvasis May 05, 2012

Hi, good work but i found a small problem.popup is not closing if we click on the form.so popup control is still showing the original location.can you guide me to solve this problem.

Posted by George Garvasis May 05, 2012

Hi, good work but i found a small problem.popup is not closing if we click on the form.so popup control is still showing the original location.can you guide me to solve this problem.

Posted by George Garvasis May 05, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts