Reputation: 2861
I have develeped a DataSet to access information from SQL for a desktop application (using WinForms).
Binding data to a ComboBox is nothing new but as i have done most of in ASP.Net, some classes that i would have used just are not available for WinForms, evidently.
So Basically, i need to know what i need to do to bind a combobox to a DataTable and then add a custom item to Index=0
, basically states "Select MC". This item will be checked against on SelectionChange but i need to have a Nullification ListItem in the set so i can invalidate the conditional refinement.
I have 3 comboboxes and 1 datagridview. The 3 comboboxes can refine the visible list of information in the gridview but i also want the user to have the ability to unselect their choice.
Here is what i tried and not getting anywhere:Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
'cboMC.Datasource = Me._mc.GetMC().AddMCRow("Select MC") <-- Did not Work
cboMC.DataSource = Me._mc.GetMC()
cboMC.Items.Insert(0, New Object() {"Select MC"}) <-- Current Try
...
End Sub
Any other suggestions? Again this is a WinForms
application and not WebForms
.
cboMC.Items.Add("Select MC")
cboMC.Items.AddRange(Me._mc.GetMC().ToArray())
Derivative of above making sure Invalidator is at index 0
cboMC.Items.AddRange(Me._mc.GetMC().ToArray())
cboMC.Items.Insert(0, "Select MC")
Worked like a charm....thans for putting me on the correct path.
Upvotes: 1
Views: 2981
Reputation: 121
I don't recall the exact syntax, but what I have done is something along the lines of:
Upvotes: 2