Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > classic combobox problem
 

classic combobox problem

If you are binding a combobox to a datasource how can you add the infamous "select one" as the first visible selection. I have done this for webforms using the 'listitem" but it seems that this need has been overlooked for windows forms.

Thanks

PatC

pat capozzi  Wednesday, February 07, 2007 8:02 AM

Hi, pat capozzi

Try something like this:

d = 63.5;

this.comboBox3.Items.Add("aa");

this.comboBox3.Items.Add(1);

this.comboBox3.Items.Add(d);

this.comboBox3.SelectedItem = d;

//this.comboBox3.SelectedItem = 1;

//this.comboBox3.SelectedItem = "aa";

Hope it helps.
Best Regards.
Ye

Zhi-Xin Ye  Thursday, February 08, 2007 4:19 AM

Hi pat :

Item can't be modified when the combobx set datasource, so do you mind add first row at your datatable as "select" ,

thento show it in the combobox

Bob zhu - SJTU  Wednesday, February 07, 2007 8:43 AM

Thanks Bob,

Yes that is a solution, but in Framework 2.0 how do you add an Item to a non bound combobox when the only parameter that the Item.Add method takes is an object.

pat capozzi  Wednesday, February 07, 2007 2:20 PM

Hi, pat capozzi

Try something like this:

d = 63.5;

this.comboBox3.Items.Add("aa");

this.comboBox3.Items.Add(1);

this.comboBox3.Items.Add(d);

this.comboBox3.SelectedItem = d;

//this.comboBox3.SelectedItem = 1;

//this.comboBox3.SelectedItem = "aa";

Hope it helps.
Best Regards.
Ye

Zhi-Xin Ye  Thursday, February 08, 2007 4:19 AM

You can use google to search for other answers

Custom Search

More Threads

• How to bind a DataGridViewComboBoxColumn?
• datagridview sorting
• Set SelectedIndex for a DataGridViewComboBoxColumn
• Refresh issues in custom painting DGV
• TableAdapter.Update doesn't update Database
• DataGridView - Excel copy & paste
• Limit bound fields in custom databound business object.
• Master-Detail Binding Support for Custom Object Datasources??? (for DataGridView’s)
• ODBC Connection String
• DataGridView -- deny user ability to resize column headers?