|
I'm about at my wits end. Years ago, I used Visual FoxPro and did this with no trouble. Now I'm using C# and pulling my hair out. The issue is as follows: Problem : Inability to correctly populate a value list from one table but select a default value from a key in another table, and update the key in the other table when a user selects a different value in the Combobox. Platform : I'm using Visual Studio 2008 with C# 3.0, .NET Frameworks 3.5. The databases/tables are SQLite. The tables : I have one table (MasterTable) that contains various rows of information. Another table (ChildTable) contains records that are connected to the MasterTable by a key. For example, MasterTable contains a field called ChildKey, ChildTable's records contain a value in a field named UniqueKey. The MasterTable ChildKey contains the ChildTable UniqueKey. This is a one-to-one relationship. I do not have Primary Keys set in visual studio. Goal : I would like to place a Combobox on my form that contains a list of records from ChildTable. When the form is loaded, a certain record in MasterTable is already selected, and several textboxes, etc. on the form are updated with values from that record/row. I want the default value in the Combobox to reflect the ChildTable record identified by the ChildKey field in MasterTable. If the user selects a different value in the combobox, I want to update the ChildKey field with the corresponding UniqueKey from the ChildTable entry that they have selected. I initially tried setting DataSource to ChildTableBindingSource, DataMember to Text, ValueMember to UniqueKey, and SelectedValue to MasterTableBindingSource-ChildKey. I have also made several different attempts by coding. The best I have done correctly populates the ComboBox but does not select the appropriate value as default and does not update the MasterTable-ChildKey if the user selects a different value. My questions : 1. How do I get this to work? It seems like it should be a fundamental thing to use a Combobox in this manner, but I'm not having much luck. 2. Can this be done without doing any special coding (i.e. in the visual tool by modifying property values such as DisplayMember only?) or do I need to include C# code to populate, etc.? The reason I ask is because way back in FoxPro, this scenario could be done simply by dragging a combobox onto a form and updating the properties. In the meantime, if I figure it out, I will post my solution here for others to read. - Moved byVMazurMVPMonday, July 27, 2009 10:04 AM (From:ADO.NET Data Providers)
-
| | BrentMC Saturday, July 25, 2009 7:23 PM | What you initially tried should work. You can do this with the designer. Just select the ComboBox and then click the smart tag. It should give you a dialog to help you pick the appropriate keys for DataMember, ValueMember, and SelectedValue. Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | DeborahK Monday, July 27, 2009 6:17 PM | Hi,
Base on my understanding, you want to show master-detail information. You need to build a relationship between the Master Table and Child Table.
The following is something about that.
1.Build Data Relation between two tables:
FAQ 31: How do I show master-details?
Master is bound to the dataset. Child is bound to the bindingsource of Master, DataMember is the relationship. When you select a value in the master table, the child table will show the details according to the relationship.
2. Filter
FAQ 27: How do I have a combo box column display a sub set of data based upon the value of a different combo box column?
When child combobox get focus, filter the bindingsource according to the master content.
Besides, as @Deborahk said, you can use the smart tag and modify the properties to implement this function.
If I misunderstood you, or you have further questions, please feel free to tell me.
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Edited byLing WangMSFT, ModeratorSunday, August 02, 2009 1:54 PM
- Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | Ling Wang Saturday, August 01, 2009 8:22 AM | Thank you both for the responses! It looks as if this largely works as described above. The only issue is that the MasterTable->ChildKey does not get updated automatically, so I had to write code to do that. This is not a big deal, but makes me think I am missing something still. Brent
- Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | BrentMC Sunday, August 02, 2009 3:50 PM | What you initially tried should work. You can do this with the designer. Just select the ComboBox and then click the smart tag. It should give you a dialog to help you pick the appropriate keys for DataMember, ValueMember, and SelectedValue. Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | DeborahK Monday, July 27, 2009 6:17 PM | Thank you, DeborahK. I'll try that tomorrow. I had put this issue aside for now, not being able to resolve it, but it has to be resolved before this project is finished. I will try it in the morning as you described and see what results I get. Thank you tremendously for the response!
- Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
- Unmarked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | BrentMC Tuesday, July 28, 2009 4:10 AM | Hi,
Base on my understanding, you want to show master-detail information. You need to build a relationship between the Master Table and Child Table.
The following is something about that.
1.Build Data Relation between two tables:
FAQ 31: How do I show master-details?
Master is bound to the dataset. Child is bound to the bindingsource of Master, DataMember is the relationship. When you select a value in the master table, the child table will show the details according to the relationship.
2. Filter
FAQ 27: How do I have a combo box column display a sub set of data based upon the value of a different combo box column?
When child combobox get focus, filter the bindingsource according to the master content.
Besides, as @Deborahk said, you can use the smart tag and modify the properties to implement this function.
If I misunderstood you, or you have further questions, please feel free to tell me.
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Edited byLing WangMSFT, ModeratorSunday, August 02, 2009 1:54 PM
- Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | Ling Wang Saturday, August 01, 2009 8:22 AM | Thank you both for the responses! It looks as if this largely works as described above. The only issue is that the MasterTable->ChildKey does not get updated automatically, so I had to write code to do that. This is not a big deal, but makes me think I am missing something still. Brent
- Marked As Answer byBrentMC Sunday, August 02, 2009 3:50 PM
-
| | BrentMC Sunday, August 02, 2009 3:50 PM |
|