I have a DataGridView (dgwList), into which I load set of items. It's an intermediate form, where user needs to select Action and Category, for which I created DataGridViewComboBoxColumns and set them in Form_Load event like this:
dtCats = ds.Tables(0) ' Datatable with Categories
dtActions = ds.Tables(1) ' Datatable with Actions
Dim colCat As DataGridViewComboBoxColumn = Me.dgwList.Columns("Category")
Dim colActions As DataGridViewComboBoxColumn = Me.dgwList.Columns("Action")
colCat.ValueMember = "ID"
colCat.DisplayMember = "CategoryText"
colCat.DataSource = dtCats
colCat.DataPropertyName = "Category"
colActions.ValueMember = "ID"
colActions.DisplayMember = "Action"
colActions.DataSource = dtActions
colActions.DataPropertyName = "Action"
Everything works fine, when I load items (using another dataset) without default values of Action and Category, I can select them from the DropDownList. However, when I load the second dataset (ds) and use i.e. "Action" to load a value as a default SelectedValue like this:
Dim cmdtext As String = "SELECT ****, 2 as Action, *** WHERE ****; "
Dim ds As DataSet
ds = DAL.GetQueryResults(cmdtext) ' using own Data Access Layer to get dataSet
Me.dgwList.AutoGenerateColumns = False
Me.dgwList.DataSource = ds.Tables(0) ' load the data table
I get "Datagridviewcomboboxcell Value Is Not Valid" error. It seems, that it tries to load it as DisplayMember, or simply a Text property of the DatGridViewComboBoxCell, as it appears as selected text.
I spend a lot of time browsing forums and I found nothing related to dataset (except Set selectedValue in DataGridViewComboBoxColumn where was missing DataPropertyName). Everything is about loops and events raised by user over the comboboxcell.
I would like to avoid the error and use the dataset (not looping to modify each cell) to fill the default values of comboboxes. Any idea?