ComboBox databindng Problem
== How the ComboBox is setup and used:
My comboBox is populated by a lookup table. The ValueMember is the
lookup table's Id and the DisplayMember is the text from a
corresponding field in the lookup table. In my data table we store the
ID in what I will call the 'key' field.
== Description of the desired operation:
1.) When the user selects a record in the datagrid the bound comboBox
displays the DisplayMember of the corresponding Value stored in the
data table's 'key' field.
2.) When the user selects a record in where the 'key' field is null (no
selection was made or saved) the comboBox display should be empty to
indicated that fact.
== Description of the problem:
Simply put, #2 above does not happen. Here is what does; When the user
moves to a record in the datagrid in which the 'key' field is null the
comboBox is *not* empty, it incorrectly displays the first possible
selection in the comboBox.
== Additional facts: (read carefully - this could be a little
confusing)
Consider a scenario in which the 1st record stores a value in the 'key'
field and in the 2nd and 3rd records in which the 'key' field is null.
Here is what happens when we walk through the records;
In the 1st record: the comboBox always displays the correct value
corresponding to the 'key' field.
As the user moves to the 2nd record: incorrectly - values are shown
rather than being empty.
As the user moves to the 3rd record: correctly - the comboBox is shown
empty.
As the user moves back to the 2nd record: correctly - the comboBox is
shown empty this time.
In summary - when you move from a record with a populated 'key' to a
record with a null 'key' field - incorrect values will *always* be
displayed. When you move from record with a null 'key' field to another
record with a null 'key' field - correctly a *blank* will *always* be
displayed in the comboBox. Records with a populated 'key' filed will
*always display correct values.
What is the reason for the wrong display behavior?
What is the solution to get proper display behavior?
=============== =========
BTW - Here is the order in which I populate and bind the controls and
datagrid.
1.) populate the dataset with the datatables for the datagrid, controls
and the combobox
2.) set the combobox datasource, value and display members
3.) set the datagrid datasource and datamember
4.) bind the controls to the datatable and corresponding field
5.) set the binding context to the datatable
== How the ComboBox is setup and used:
My comboBox is populated by a lookup table. The ValueMember is the
lookup table's Id and the DisplayMember is the text from a
corresponding field in the lookup table. In my data table we store the
ID in what I will call the 'key' field.
== Description of the desired operation:
1.) When the user selects a record in the datagrid the bound comboBox
displays the DisplayMember of the corresponding Value stored in the
data table's 'key' field.
2.) When the user selects a record in where the 'key' field is null (no
selection was made or saved) the comboBox display should be empty to
indicated that fact.
== Description of the problem:
Simply put, #2 above does not happen. Here is what does; When the user
moves to a record in the datagrid in which the 'key' field is null the
comboBox is *not* empty, it incorrectly displays the first possible
selection in the comboBox.
== Additional facts: (read carefully - this could be a little
confusing)
Consider a scenario in which the 1st record stores a value in the 'key'
field and in the 2nd and 3rd records in which the 'key' field is null.
Here is what happens when we walk through the records;
In the 1st record: the comboBox always displays the correct value
corresponding to the 'key' field.
As the user moves to the 2nd record: incorrectly - values are shown
rather than being empty.
As the user moves to the 3rd record: correctly - the comboBox is shown
empty.
As the user moves back to the 2nd record: correctly - the comboBox is
shown empty this time.
In summary - when you move from a record with a populated 'key' to a
record with a null 'key' field - incorrect values will *always* be
displayed. When you move from record with a null 'key' field to another
record with a null 'key' field - correctly a *blank* will *always* be
displayed in the comboBox. Records with a populated 'key' filed will
*always display correct values.
What is the reason for the wrong display behavior?
What is the solution to get proper display behavior?
=============== =========
BTW - Here is the order in which I populate and bind the controls and
datagrid.
1.) populate the dataset with the datatables for the datagrid, controls
and the combobox
2.) set the combobox datasource, value and display members
3.) set the datagrid datasource and datamember
4.) bind the controls to the datatable and corresponding field
5.) set the binding context to the datatable