Add combobox to datagridview from designer

SteveInBeloit

Well-known member
Joined
May 22, 2006
Messages
132
Programming Experience
10+
HI,
I have a form with two datagridviews. I am adding a column to the second datagridview. I went to Edit Columns and clicked add, and set it as type comboBox.

For the data properties:

DataPropertyName: the column in the datagridview table that corresponds to the column in the other table I want to get the value from.
DataSource: drilled down to Other Data sources, project data source, then my databse, then clicked on the table I want to look the values up in.

displaymember: the actual description I want the user to see from the table above.

valuemember: the column in the table from above, not from the datagridview


when I run it, I get a system.formatException: DatagridviewcomboBox cell value is not valid

any thoughts?
 
is the type of the column chosen for the ValueMember compatible with the type of the column chosen for DisplayPropertyName ?
 
In designer, when I edit the combo box to set the datasource, I drill down through other sources until I find my table and select it. That puts a tblMyTablebindingSource1 on the form. But there is no adapter? Should their be? How is it getting filled?

I put a DataError handler in it, it shows "Formatting Display".

I put this same table in a datagridview on a different form, and set it up the same way. It works fine. They are set up the same. Also, in the form where it won't work, it happens to be on the child of two datagridviews.
 
Last edited:
Yep, kind of a scattered post.

I have two tables in the data source, they have a relation. I have dragged the first one to the form as a datagridview. I dragged the second one to the form. I run this, and it works. As I select the parent rows, the child rows change appropriately.

In designer, I can see both datagridviews. There is a difference between the two. On the parent one, I can see the column headers, then one row underneath. Not of data, just a white row with the add * on the left, and in each cell, you can tell what type it is, a button if a buttoncell, a check box, or blank for a text box. In the child datagridview, I see the headers, but that is it, the blank white row is not present. (Don't know if that matters) Readonly is false on both.

In the child view, I added a combobox column. Set the Data Source to a table, then set the datapropertyname, displaymember, and valuemember. I have checked these many times, and believe them to be right.

When I run this, I get the parent table populated correctly. If I click on a row that has no child rows, they child datagridview looks OK. When I click on a row that has child rows, I get one error message for each row in the child table saying Formatting Display. (From my error handler). Then it displays the row with the keyvalue in the combo box.

I opened a second form, and just dragged the child table to it, followed the same steps, and added the combo box. Seems to work fine.

I have read everything I can find, I just can't get this to work. . .

Thanks for reading.
Steve
 
Yep, kind of a scattered post.

I have two tables in the data source, they have a relation. I have dragged the first one to the form as a datagridview. I dragged the second one to the form. I run this, and it works. As I select the parent rows, the child rows change appropriately.

In designer, I can see both datagridviews. There is a difference between the two. On the parent one, I can see the column headers, then one row underneath. Not of data, just a white row with the add * on the left, and in each cell, you can tell what type it is, a button if a buttoncell, a check box, or blank for a text box. In the child datagridview, I see the headers, but that is it, the blank white row is not present. (Don't know if that matters) Readonly is false on both.
White row not present normally indcates that allow new rows is false. It is the default appearance for a child datagridview

In the child view, I added a combobox column. Set the Data Source to a table, then set the datapropertyname, displaymember, and valuemember. I have checked these many times, and believe them to be right.
You added a column, or you changed an existing column? Adding a column might be a problem unless you are sure you set the column to map to something, otherwise it will be just full of NULLs, which your combo might not have trouble displaying .. I suggest you add your column as a textbox first, then convert it to a combo later, after ensuring it shows the data youre expecting for the valuemember. When adding the combo, ensure the data table it sources its info from, is populated

Can I suggest that you REMOVE the error handler and let it post the full detail it normally would, then screenshot this and lpost the shot here.. ?
 
I went back and removed the DataError handler. Then I removed my combobox, and changed the column that contains the key to the other table to a combo box. And set it up as I had the one I added. The error it throws says: (i don't know how to post the picture)

DataGridView Default Error Dialog
The following exception occurred in the DataGridView:
System.FormatException: DatagridViewComboBoxCell vaule is not valid.
To replace this default dialog pleas handle the DataError event.

I checked that those keys are present in the other table. They are. And it works on the other form with the same data.
 
There will be some small, silly thing like, not filling the data table that the combo uses for its data source..

If you have msn, I can take a look via remote assistance..
 
Trying to attach the project, it is the Operators tab on the Tailoring form.
Well, I keep trying to attach it. The attachment pop up comes up, I browse to my .zip, select it, then hit upload. Sits there for a minute, then the pop up goes all white. Can't tell if it is working.
 
What size is the zip? Remove all BIN and OBJ folders before uploading, use Best compression, pare down databases to just the minimum tables necessary to demonstrate the issue..
Remember that Neal pays for the bandwidth of this forum, so strip out your project as much as possible
 
Man, I am just not catching on to these combo boxes. I still can't get passed the errors. So I went to another form, and changed another text box to combo box. This datagridview is based on the Tasks table. That field holds a description of a location. For the datasource, I drilled down to the Locations table. Datapropertyname is the colomn in the Tasks table, a decription from the locations table. In desplaymember I put the desc. from the Loc. table. In the value member, I put the desc. from the Loc. table as well, as they join on the actual description column in this example. When I run the form, a whole page displays, but I get that "value not valid" message once. As I scroll down, I get it some more. What could possibly be making it think those descriptions are not valid to put in that Cell??

I am assuming this is the same problem I am having with the other form.....
 
More comboBox woes.....

I have almost everything done in this project, except the functionality around the combo boxes. I just can't get by the error listed above.
Here is what I have done to try to solve this.

I created another project with one form. When I atatched the the Data Source, I just selected the two tables. From the DataSource, I dragged the first table over. I edited and change a column to a comboBox. I then filled out all the properites as I was doing on the problem one. Works fine.

I went back to my main project, added one additional form and went through the exact same steps as above, except my project is already hooked to the data source with all the tables and procs. I still get the format error when I run this.

I did a file compare between the two forms, or the three .vb files I mean, no differences you would not expect.

Another difference between the two is that the one that won't work is that the one that won't work is on a child DGB attached to a parent DGV via a relation in the table.

any idea?
Steve
 
Last edited:
Back
Top