How To Show A multiple Columns In Combo Box Using

private void Form1_Load(object sender, System.EventArgs e)
con=new SqlConnection(@”Data Source=SYS-D1\SQLEXPRESS;Initial Catalog=sam;Integrated Security=True;Pooling=False”);
cmd=new SqlCommand(“select * from details”,con);
ada=new SqlDataAdapter(cmd);
ds=new DataSet();
DataTable myDataTable=new DataTable(“details”);

//Demo the functionality of the ColumnComboBox
#region Create DataTable
// Create a new DataTable add some rows and then put it into myColumnComboBox.
//Of course this is far easier when done with a query of some sort to create the DataTable automaticaly.

//System.Data.DataTable myDataTable = new DataTable(“ParentTable”);
// Declare variables for DataColumn and DataRow objects.
DataColumn myDataColumn;
DataRow myDataRow;

//Add some coulumns
for(int index = 0; index < myDataTable.Columns.Count; index++)
//myDataColumn.Caption = “ParentItem”;
//myDataColumn.AutoIncrement = false;
//myDataColumn.ReadOnly = false;
//myDataColumn.Unique = false;
// Add the Column to the DataColumnCollection.


//Add a row
//myDataRow = myDataTable.NewRow();
int iCol = 0;
//foreach(DataColumn dc in myDataTable.Columns)
//    myDataRow[dc.ColumnName] = “Blah Blah Column: ” + iCol;
//    iCol++;
////Add another row
//iCol = 0;
//myDataRow = myDataTable.NewRow();
//foreach(DataColumn dc in myDataTable.Columns)
//    myDataRow[dc.ColumnName] = iCol + ” Another row”;
//    iCol++;
//Add some more rows
for (int index = 0; index<= myDataTable.Rows.Count; index++)
myDataRow = myDataTable.NewRow();
iCol = 0;
foreach(DataColumn dc in myDataTable.Columns)
myDataRow[dc.ColumnName] = “Row: ” + index + ” Column: ” + iCol;
//Add another row
//iCol = 0;
//myDataRow = myDataTable.NewRow();
//foreach (DataColumn dc in myDataTable.Columns)
//    myDataRow[dc.ColumnName] = “Last Row Col” + iCol;
//    iCol++;

//Now set the Data of the ColumnComboBox
myColumnComboBox.Data = myDataTable;
//Set which row will be displayed in the text box
//If you set this to a column that isn’t displayed then the suggesting functionality won’t work.
myColumnComboBox.ViewColumn = 2;
//Set a few columns to not be shown
//myColumnComboBox.Columns[1].Display = false;
//myColumnComboBox.Columns[3].Display = false;

private void myColumnComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
//You can get data from the selected row out of the ColumnComboBox like this:
if(myColumnComboBox.SelectedIndex > -1)//If there is no selected index the indexer will return null
txt1.Text = myColumnComboBox[“Column0″].ToString();
txt2.Text = myColumnComboBox[“Column3″].ToString();

About these ads

About developersite
I am Dot Net Programmer

2 Responses to How To Show A multiple Columns In Combo Box Using

  1. harini says:

    i need a detailed explanation i am not able to understand pls give complete coding has example

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: