By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,839 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,839 IT Pros & Developers. It's quick & easy.

How Do I Clear Combobox Contents Within A DataGridView After Filling It?

P: 1
My DataGridView has two columns. Combobox Column 2 displays list based on Combobox Column 1 selected value. The code below works fine when I select a value on Column 1, and select a value on Column 2. But on the next row, when I leave Column 1 blank and click on Column 2, it generates error DataGridViewComboBoxCell value is invalid. And the code below works fine the first time I click Column 2, leaving Column 1 blank.

I just want to display empty Combobox after displaying a filled Combobox.

How do I do that? Thanks in advance.

Here is my code:

Private Sub dgDE_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArg s) Handles dgDE.CellMouseClick
Dim dgvc As DataGridViewComboBoxColumn
Dim ds As New DataSet

If myConn.State = ConnectionState.Closed Then myConn.Open()
dgvc = New DataGridViewComboBoxColumn
'Populate Status Combobox
If e.ColumnIndex = 0 Then
ds = getDS("select Code, [Desc] from su_Status")
ds = getDS("select Code, [Desc] from su_Statistics where StatCode='" & Trim(dgDE.Rows(e.RowIndex).Cells(0).Value()) & "'")
End If
With dgDE
dgvc = .Columns(e.ColumnIndex)
dgvc.DisplayMember = "Desc"
dgvc.ValueMember = "Code"
dgvc.DataSource = ds.Tables(0) '<-- the error fires here
End With
End Sub
Jul 26 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.