|
-
Feb 27th, 2007, 01:34 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Problem with DataGridViewComboBox
I am using a DataGridViewComboBox in a DataGridView. When a user selects a radio button, I would like to clear all the items in the DataGridViewComboBox and repopulate with new values. I do this as follows:
Code:
Dim iIndex As Integer
Dim dgcb As DataGridViewComboBoxCell
For iIndex = 0 To dgvRecipe.RowCount - 1
dgcb = dgvRecipe.Rows(iIndex).Cells("Measure")
dgcb.Items.Clear()
If radEnglish.Checked Then
dgcb.Items.AddRange(New String() {"t", "T", "Cup", "Quart", "Gallon", "oz", "lbs"})
Else
dgcb.Items.AddRange(New String() {"mg", "g", "ml", "Litre"})
End If
Next iIndex
It appears to do the job, but later while the control is refreshing i get the error:
The following exception occured in the DataGridView:
System.ArguementException: DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle the DataError event.
Any ideas?
-
Feb 27th, 2007, 05:33 PM
#2
Re: Problem with DataGridViewComboBox
Let's say that your RadioButton is intially unchecked. That means that your combo box contains "mg", "g", "ml" and "Litre". Let's say that the user selects "mg" in one particular cell. Now let's suppose that the user checks the RadioButton. Your code will clear out the existing combo box items and add "t", "T", "Cup", "Quart", "Gallon", "oz" and "lbs". One of your cells still contains the value "mg" but that value is not contained in the combo box item list. That's what the error message is telling you. Your cell contains an invalid value, i.e. one that is not listed in the combo box.
If you're going to change the list of items in the combo box then you first need to clear all the cell values in that column because none of them will be valid afterwards.
-
Feb 27th, 2007, 05:53 PM
#3
Thread Starter
Addicted Member
Re: Problem with DataGridViewComboBox
Thanks!
That was indeed the problem!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|