1st combo box item selected in Form_Load after Data Bind.

D

David R

Hi,

This would seem to be a variation on a well known issue
with .NET Windows Forms Combo Boxes, however, I was
wondering if anyone has had any success with it in the
mean time.

I have a combo box which I data bind in the Form_Load
event. The 1st item in the data source is selected.
However, for my purposes, the combo box should have no
selected item. Setting the SelectedIndex property to -1
has no effect. The 1st item is still selected. Here is my
code :

private void JobViewWinForm_Load(object sender,
System.EventArgs e)
{
....

// Populate Job Status Combo. Deselect item.
DataSet __JobStatusDataSet =
JobBusinessObject.RetrieveJobStatus();
jobStatusComboBox.DataSource =
__JobStatusDataSet.Tables[0];
jobStatusComboBox.ValueMember = "JobStatusID";
jobStatusComboBox.DisplayMember = "Description";
jobStatusComboBox.SelectedIndex = -1;

// Setup DataGrid - Do search for all jobs.
//Search();

....

}

I would like to have the combo box unselected,
particularly, because the Search method looks at the combo
to see if anything is selected. But, of course, on
Form_Load, nothing should be.

Thanks,
David.
 
H

Herfried K. Wagner [MVP]

* "David R said:
This would seem to be a variation on a well known issue
with .NET Windows Forms Combo Boxes, however, I was
wondering if anyone has had any success with it in the
mean time.

I have a combo box which I data bind in the Form_Load
event. The 1st item in the data source is selected.
However, for my purposes, the combo box should have no
selected item. Setting the SelectedIndex property to -1
has no effect. The 1st item is still selected. Here is my
code :

Set 'SelectedIndex' to -1 /twice/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top