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

DataGridView Combobox column Error

P: n/a
I've populated all the cells in a combo box column with values from 1 -
50 using the following code:

foreach (DataGridViewRow row in uxTabSummary.Rows)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)
row.Cells["numRows"];
for (int i = 1; i < 51; i++)
{
cell.Items.Add(i);
}
}

However, after the user changes a value in the drop down combo box, and
moves the focus to another cell, a "System.ArgumentException:
DataGridViewComboBoxCell value is not valid".

Googling shows an extensive number of people suffering the same, but
I'm none the wiser.

Is there a simple solution to this?

Greg.

Jul 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Greg wrote:
I've populated all the cells in a combo box column with values from 1 -
50 using the following code:

foreach (DataGridViewRow row in uxTabSummary.Rows)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)
row.Cells["numRows"];
for (int i = 1; i < 51; i++)
{
cell.Items.Add(i);
}
}

However, after the user changes a value in the drop down combo box, and
moves the focus to another cell, a "System.ArgumentException:
DataGridViewComboBoxCell value is not valid".

Googling shows an extensive number of people suffering the same, but
I'm none the wiser.

Is there a simple solution to this?

Greg.
Perhaps you can try adding a DataTable to hold all those values for the
ComboBox, then setting the ComboBoxColumn.DataSource to the DataTable.
The ComboBoxColumn.ValueMember's data must be valid for the underlying
column in the DataGridView.

B.

Jul 26 '06 #2

P: n/a
Great, thanks!

Brian Tkatch wrote:
Greg wrote:
I've populated all the cells in a combo box column with values from 1 -
50 using the following code:

foreach (DataGridViewRow row in uxTabSummary.Rows)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)
row.Cells["numRows"];
for (int i = 1; i < 51; i++)
{
cell.Items.Add(i);
}
}

However, after the user changes a value in the drop down combo box, and
moves the focus to another cell, a "System.ArgumentException:
DataGridViewComboBoxCell value is not valid".

Googling shows an extensive number of people suffering the same, but
I'm none the wiser.

Is there a simple solution to this?

Greg.

Perhaps you can try adding a DataTable to hold all those values for the
ComboBox, then setting the ComboBoxColumn.DataSource to the DataTable.
The ComboBoxColumn.ValueMember's data must be valid for the underlying
column in the DataGridView.

B.
Jul 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.