Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Data Binding Best Practices
 

Data Binding Best Practices

Hello:

I've a question regarding best practices and data binding.

Let me quickly describe my two data structures. I have two Person and Country. The Person data structure contains a List<Country>, which indicates what countries the person has visited.

Now onto my UI.

Assume I have a List<Person>, which represents ALL people in a specific category. I bind the List<Person> to a ComboBox.

Now, I also have a separateList<Country>, which is a list of ALL countries in the world. Now, I'm binding this list to a DataGridView. In the DataGridView, I have two columns: one displaying the country's name and another that is a check box. Again, allcountries are displayed in the DataGridView. This DataGridView is just a selection that indicates WHAT COUNTRIES the person has visited.

Therefore, when the program is ran, initialization occurs: the combo box is populated with ALL users and the DataGridView is populated with ALL countries.When the user selects a person from the ComboBox, the countries the person has visited, which is stored in the Person's List<Country>should be checked. The user can uncheck and check countries; in the background, the Person data structure is adding or removing data objects of type Country from the Person's List<Country>.

What is the proper way to accomplish this scheme using DataGridView?

Thank you.


Trecius
Trecius  Friday, July 24, 2009 9:58 PM
Hello Trecius,
The way you are doing right now; its fine.
You have to handle selectedIndexChanged and in that,

1) update List<country> of previous person(you need to use one temp variable to store selected person).

2) loop through List<Country> of new person, and check uncheck datagridviewcheckboxcell accordingly.

and then set tempPerson = selectedPerson
NareshG  Saturday, July 25, 2009 9:54 AM
Hello Trecius,
The way you are doing right now; its fine.
You have to handle selectedIndexChanged and in that,

1) update List<country> of previous person(you need to use one temp variable to store selected person).

2) loop through List<Country> of new person, and check uncheck datagridviewcheckboxcell accordingly.

and then set tempPerson = selectedPerson
NareshG  Saturday, July 25, 2009 9:54 AM

You can use google to search for other answers

Custom Search

More Threads

• How to merge cells in datagridviw?
• What is BindingSource?
• Deleting columns from a data bound DataGridView.
• Filter DataGridview between two dates by using datetimepicker control in form
• DataGridView Sort Problem
• DataRowBuilder
• windows application on a network
• How to put contents to two fields into one TextBox?
• How to drag information from a DataGridView control to listBox...
• Combo box and Datasource