Click here to Skip to main content
15,850,753 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using VS2010, C#, .net3.5.

I have a problem when binding data to a combobox. Let's say i have two tables with a parent-child relation, T1 (child), and T2 (parent).

I have a combobox and textbox which bind to bindingsource B2. The combobox's selectedvalue binds to a FK column in T1. In the textbox i want to depict a column from T2, corresponding with FK in T1 = PK in T2. So i want to perform a lookup in another table.

Problems arise when the FK in T1 is NULL. To which row should B2 bind? Its 'Current' property stays on the previous row and is not updated because the selectedvalue is NULL. Setting the position of B2 to -1 does not seem to help. When i navigate back to the previous row, the Current property will not be updated, because it is already there.

Any suggestions would be appreciated..!

Updated 21-Sep-10 1:05am
Venkatesh Mookkan 21-Sep-10 6:08am    
Please provide some code snippet how you are binding. Make sure you does mention the SelectedValuePath for the ComboBox
Rob van Daal 21-Sep-10 6:23am    
Hi Venkatesh,

the combobox binding:
- Datasource: bindingSourceTrpServiceInstall
- SelectedValue: bindingSourceTestReports - installation_id
- Value member: installation_id
- Display member: installation_nr

Testbox binding:
- Text: bindingSourceTrpServiceInstall - description

I don't really have a code snippet, it just implements the above. So the Problem occurs when the installation_id = NULL. The selectedvalue becomes NULL and thus bindingSourceTrpServiceInstall.Current stays on the previous record. Nevertheless, the description is emptied and an empty string is put in the previous record. Ofcourse this can be solved by disabling two way binding, but the real problem is that bindingSourceTrpServiceInstall should be pointing to no record at all when there is no installation_id. This does not seem to be always points to an existing record.

Thanks for your help,
MCY 21-Nov-10 13:24pm    
If possible, you might want to change database architecture, prevent null FK's by seperating them into another table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900