Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView ComboBox

Status
Not open for further replies.

rjoubert

Programmer
Oct 2, 2003
1,843
US
I'm developing a windows application in VB.NET 2005. I have a form with an unbound DataGridView control. One of the columns in this DataGridView is a databound ComboBox column. It retrieves records from a lookup in table in a SQL Server database. The table has a ID (numeric) field that corresponds to the ValueMember property of the ComboBox. There is also a Description (text) field that corresponds to the DisplayMember property of the ComboBox. So far, so good.

What I am trying to do now is to programatically set the SelectedValue of this ComboBox. Since this ComboBox is embedded within the DataGridView control, I am not able to set the selectedValue as I would with a ComboBox that is not embedded. I want to be able to set what is seen in the ComboBox by using the ID field, and not the Description field.

For now, I'm just using a test button on the windows form to try and work out this code. I only have one line of code in there now.
Code:
Me.datRecords.Rows(0).Cells(3).Value = 9
Here is the error that I am getting...
The following exception occurred in the DataGridView:
System.FormatException: DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle the DataError event.

Thanks in advance for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top