I have two tables feeding through one dataset: A main table with a foreign
key into a lookup table. Primary keys in both tables are defined as INTEGER
UNSIGNED NOT NULL. The foreign key in the main tables is defined as INTEGER
UNSIGNED NULL.
The main table is displayed through textboxes on the form, and a separate
Combobox displays the selected, and list of lookup values from the lookup
table. No data relations have been defined in the dataset. A bindingsource is
used, as well as a binding navigator. This part of the form works fine.
On the same form I have placed a DGV, with a subset of main table columns
and one DGVCombobox column. Initially, this worked just fine. However a minor
change to the database column names â?? not the data - has generated the
invalid DataErrors. I have defined an error handler to trap the error and
decode some information. The Column number points to the DGVCombobox, and the
Context bits decode to â??Formatting, Displayâ??.
Using the debugger to examine the details on the dataset, I noted that the
primary key for the lookup table is defined as FullName of System.Int32. The
primary key of the main table is defined as the same. However the main
tableâ??s foreign key is defined as having FullName of System.UInt32.
I have tried deleting the DGV and recreating it. The result is consistent
and the same: as each cell of the DGV Combo box is displayed, the error
exception is generated. The resulting displayed value is the foreign key
value of the main table. Recall: no constructs were changed, only the column
names were adjusted, and they have been thoroughly checked.
Here is the code to set up the DGV. DgvCpyStatus is the DGV combobox column.
dgvCpyList->DataSource = bindingSource1;
dgvCpyName->DataPropertyName="CpyName";
dgvCpyPriority->DataPropertyName="CpyPriority";
dgvCpyID->DataPropertyName="idCompany";
dgvCpyStatus->DataSource=dataSet1->Tables->default["tblStatus"];
//The next line ties the DisplayMember to the foreign key
dgvCpyStatus->DataPropertyName ="tblStatus_idStatus";
dgvCpyStatus->DisplayMember="StatusName"; //Textual status column
dgvCpyStatus->ValueMember="idStatus"; //primary key column in tblStatus