How to insert first blank row to binded ComboBox?
Hello,
I'm working on Winform application, where i have a ComboBox who is binded to some DataSet.
Now, i want a black first row in the combox (which the user will use as "I dont want to select anything!" item). how can i do it?
I tried to use the Add method of the ComboBox.Items, and it works fine but in the top of the combobox, and not in the head of it (the last item, not the first one).
Thanks alot, Liran.
Sanjay ChauhanPosted Aug 26, 2009, 1:22 AM
If u want to add text like "Select" or "None" in combo box (drop down list) in .NET framework window form control. There is no such way to add items in combo box's items property after you set DataSource. To avoid this you can add one more item in your datasource. For example if you are trying to bind combo box list through DataTable then add one more row into DataTable.
Here i am posting you sample code for adding one row into the fetched dataTable
private void BindCombo()
{
DataTable dataTable = GetDataTable();
DataRow row = dataTable.NewRow();
row["Code"] = "None";
row["Name"] = "None";
dataTable.Rows.InsertAt(row, 0);
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Code";
comboBox1.DataSource = dataTable;
}
Posted Aug 25, 2009, 3:16 PM
Kirtan PatelPosted Aug 24, 2009, 12:34 PM
you have to add New Blank Row before binding Data to the Combobox ;
Tell me The Fields and Connection String of Your Database I will Give you the Code to Bind It Programatically :)
Posted Aug 24, 2009, 11:52 AM
Kirtan PatelPosted Aug 24, 2009, 9:27 AM
Could not understood
Do you want to Add Blank at Button of The ComboBox list or At The Top of comboBox List after Dataset has Filling Data in Combobox?