WPF DataGrid cell click
-
Hello Everyone I have this slight problem maybe someone can help me please... I have created a WPF project on VS2010. In this project I have a window with one DataGrid (on the left side of the window), seven TextBoxes, two ComboBoxes and one CheckBox (on the right side of the window). When I run application, on the DataGrid I display only the name of employee from the database. My Question: How can I display all the details of the employee in the textboxes, comboboxes, and checkbox when I click on the cell of the datagrid? Could someone help me on this please I'm new to WPF... Kind Regards to everyone Lapeci
-
Hello Everyone I have this slight problem maybe someone can help me please... I have created a WPF project on VS2010. In this project I have a window with one DataGrid (on the left side of the window), seven TextBoxes, two ComboBoxes and one CheckBox (on the right side of the window). When I run application, on the DataGrid I display only the name of employee from the database. My Question: How can I display all the details of the employee in the textboxes, comboboxes, and checkbox when I click on the cell of the datagrid? Could someone help me on this please I'm new to WPF... Kind Regards to everyone Lapeci
-
You could consider presenting your data in a ListBox or a ListView and set IsSyncronisedWithCurrentItem="True" using the autamatic Parent Child binding in WPF.
-
Hello Everyone I have this slight problem maybe someone can help me please... I have created a WPF project on VS2010. In this project I have a window with one DataGrid (on the left side of the window), seven TextBoxes, two ComboBoxes and one CheckBox (on the right side of the window). When I run application, on the DataGrid I display only the name of employee from the database. My Question: How can I display all the details of the employee in the textboxes, comboboxes, and checkbox when I click on the cell of the datagrid? Could someone help me on this please I'm new to WPF... Kind Regards to everyone Lapeci
There are two ways to do this: 1. Bind the DataGrid's SelectItem to a property in your ViewModel (or code behind if you're not using MVVM :( ), then in the setter for that property populate properties for the TextBoxes, ComboBoxes etc. This method has the advantage of being able to add a Cancel button. 2. Bind the TextBoxes, ComboBoxes etc to the DataGrid's SelectedItem property. Something like this:
{Binding ElementName=DataGrid1, Path=SelectedItem.TextPropertyName}
This method saves you a bit of coding but doesn't offer an easy way to cancel changes.
-
Is any way to do it with datagrid rather then with listbox, and is it possible to show me with some sample code according to my question please... kind regards lapeci