472,802 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 software developers and data experts.

DataGridView ComboBox Binding

Hi,

I have a datagridview bound to a List of objects (ObjectA). Each ObjectA
contains an ObjectB property.

Class ObjectA
{
public ObjectB objB {}
}

The datagridview has a combobox column that is bound to each ObjectA's
ObjectB, like this:

List<ObjectA> ObjectAList = new List<ObjectA>();
....
dgv.DataSource = ObjectAList;
dgv.Columns[1].DataPropertyName = "objB";

When the datagridview loads, I get an error in the form of a message box for
each row that loads:

The following exception occurred in the DataGridView:
System.FormatException: DataGridViewComboBoxCell value is not valid.

The comboboxes all load with the right values, but this error appears as
they load and whenever the datagridview is clicked.

Does anyone know what would cause this behavior?
Apr 7 '06 #1
2 16275
Nathan,

You can not set the expression for a binding to be a method, which is
what objB is. You have to expose it as a property.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan" <Na****@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Hi,

I have a datagridview bound to a List of objects (ObjectA). Each ObjectA
contains an ObjectB property.

Class ObjectA
{
public ObjectB objB {}
}

The datagridview has a combobox column that is bound to each ObjectA's
ObjectB, like this:

List<ObjectA> ObjectAList = new List<ObjectA>();
...
dgv.DataSource = ObjectAList;
dgv.Columns[1].DataPropertyName = "objB";

When the datagridview loads, I get an error in the form of a message box
for
each row that loads:

The following exception occurred in the DataGridView:
System.FormatException: DataGridViewComboBoxCell value is not valid.

The comboboxes all load with the right values, but this error appears as
they load and whenever the datagridview is clicked.

Does anyone know what would cause this behavior?

Apr 7 '06 #2
objB is a property, as I specified in the OP. To be more specific:

private ObjectB m_objB;
public ObjectB objB
{
get {return m_objB;}
set {m_objB = value;}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

You can not set the expression for a binding to be a method, which is
what objB is. You have to expose it as a property.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Apr 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
3
by: amber | last post by:
Hello, I have 6 comboboxes, that I thought I could bind to the same datasource, and have them display different 'selectedvalue's', but apparently I can't... My code is as follows: dim drv as...
2
by: Bob | last post by:
I need to check if there has been a difference between the old value in a call of a datagridview and the new value after the user changed a selection in a combobox in the datagridview. I can find...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
0
by: BiT | last post by:
Hello i'm using the datagridview control in vb.net. one of the column is combobox i worte this code to enter value to the combobox Dim _messageId As New DataGridViewComboBoxCell ...
1
by: Trey | last post by:
I have an unbound datagridview with three comboboxes (e.g. A, B, C) All three comboboxes share the same datasource and use the same valuemember. If I change the value of say combobox A, then B and...
0
by: Dom | last post by:
I have a datagridview control, and one column is a ComboboxColumn. I simply create a ComboboxColumn, add items to it, then add the column to the Datagridview control. If I were working with a...
0
by: priyamtheone | last post by:
There's an editable datagridview populated from a table say tblItems. Among the columns of the datagridview there's a combobox column named 'Category'. This column is populated by the respective...
0
by: visweswaran2830 | last post by:
Hi, I am having datagridview in that I have datagridview combobox column and noraml textfield. I want to know that how can I load selected value in that combox box when I am loading all entered...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.