Question Datagridview selection trouble

quizkiwi

New member
Joined
Sep 14, 2009
Messages
2
Location
PA
Programming Experience
1-3
I have a datagridview on a windows form that is tied to a database. Some of the fields in the main table are just FK's of a secondary table. The datagridview binds the FK to the field, but displays the data from the secondary table instead of an ID. Now the underlying database does not require these fields to be filled in, but on the windows form, once you have selected something for that field, it will not let you remove the selection. I understand the issue...you are attempting to enter something that it does not have an ID for, but there must be a way to enter in a null ID?

Thanks for the help.
 
Your post is a bit confusing but let me start by asking about the datasource you have connceted to the datagridview control. Are you using a typed or untyped dataset or a datatable? How are the column properties for this defined in your front end?

For instance you can have a typed dataset with one or many tables defined within it. You can set columns to identity seeds. These identity seeds can be primary or foreign keys to other tables and you can set them to use negative value on the front end that will be replaced with there proper key values when you update to the database.

This may or may not be your problem but without a more detailed explaination and/or providing some of your coding for an example, I'm taking a guess for a starting spot.

Also what part of PA are you from?
 
I apologize for the confusion.

I have an access database that is connected to the project through a typed dataset. This has a binding source and table adapter for each table in the database. The columns are set as a collection, some of the field pulled directly from the main table, others are drop down boxes with a datasource from a different table. The display member is the data held in field two of that different table, but the value member is the ID field of that table. Below is an example since I am not making this clear:

Table1:
Field1(ID)
Field2(Foreign Key from Table2)

Table2:
Field1(ID)
Field2(String)

So when you are looking at the datagridview, each record has Table1Field1 in the first column and a dropdown box of Table2Field2 values. You select one and it in turn updates Table1 with Table2Field1. A simple relational database is all.

The access database specifies Table1Field2 as not required. So you can create a new record using the datagridview with only the Table1Field1 specified and this works fine. The issue comes when you select something from the dropdown box and then decide later that you wanted to leave it blank. You cannot delete it because the only options are the list from Table2.

I am fully aware that this problem may be a result of poor design, but I do not know better and I am not sure what code to show you as much of the datagridview was created using the designer. Is there some specific part of the code that I should show?

I understand the piece about the front end holding the values until the database is updated, I thought this is what I was doing with the tableadapter.update function?

Thanks for the help, let me know how I can clarify more.
 
Back
Top