Reputation: 1
I have a DataTable that I am querying data from a database with, and then I am going through each line, and adding a row and applying the values to each row for already existent values. When this line runs
DirectCast(DataGridView1.Rows(i).Cells("Key Field 1 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield1"))
DirectCast(DataGridView1.Rows(i).Cells("Key Field 2 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield2"))
DirectCast(DataGridView1.Rows(i).Cells("Key Field 3 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield3"))
It sets the .value of the field properly, but it does not set the value on the dropdown, so the value can't be seen. I have a data_error handler, and it is not being fired, so it is not due to the incorrect datatype, and if I select a value from the dropdown, even the value it is supposed to load as, it does change .value and it saves to the database properly, but I can't seem to find a way to set the selecteditem to the value it needs to be.
Full block of code is here:
If dt.Rows.Count > 0 Then
For Each row As DataRow In dt.Rows
If CStr(row("RATETYPE")).ToUpper() = "HEADER" + RateType Then
handleHeaderRow(row)
ElseIf CStr(row("RATETYPE")).ToUpper() = RateType Then
DataGridView1.Rows.Add()
DataGridView1.Rows(i).Cells("cuid").Value = CStr(row("cuid"))
DataGridView1.Rows(i).Cells("Key Field 1 text").Value = CStr(row("keyfield1"))
DataGridView1.Rows(i).Cells("Key Field 2 text").Value = CStr(row("keyfield2"))
DataGridView1.Rows(i).Cells("Key Field 3 text").Value = CStr(row("keyfield3"))
DirectCast(DataGridView1.Rows(i).Cells("Key Field 1 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield1"))
DirectCast(DataGridView1.Rows(i).Cells("Key Field 2 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield2"))
DirectCast(DataGridView1.Rows(i).Cells("Key Field 3 cmb"), DataGridViewComboBoxCell).Value = CStr(row("keyfield3"))
DataGridView1.Rows(i).Cells("Rate 1").Value = CDbl(row("rate1")).ToString("F2")
DataGridView1.Rows(i).Cells("Rate 2").Value = CDbl(row("rate2")).ToString("F2")
DataGridView1.Rows(i).Cells("Rate 3").Value = CDbl(row("rate3")).ToString("F2")
DataGridView1.Rows(i).Cells("Rate 4").Value = CDbl(row("rate4")).ToString("F2")
DataGridView1.Rows(i).Cells("Rate 5").Value = CDbl(row("rate5")).ToString("F2")
i += 1
End If
Next row
End If
Upvotes: 0
Views: 108