SIGN UP MEMBER LOGIN:    
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
share this article :
post comment
 

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

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
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor