Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Selecting Rows in a Datagrid
2 replies. Latest Post by yifung on June 28, 2009.
(0)
Darren9962
Member
5 points
24 Posts
06-27-2009 10:28 AM |
I've got a bound datagrid with columns like so:
PharmacyList.Columns.Add(new DataGridCheckBoxColumn { Binding = new Binding("Selected") }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("PharmacyID"), IsReadOnly = true, Visibility = Visibility.Collapsed }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "City", Binding = new Binding("PharmacyCity"), IsReadOnly = true }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "Zip", Binding = new Binding("PharmacyZIP"), IsReadOnly = true }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("PharmacyName"), IsReadOnly = true }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "Address", Binding = new Binding("PharmacyAddr"), IsReadOnly = true }); PharmacyList.Columns.Add(new DataGridTextColumn { Header = "Fax Number", Binding = new Binding("FaxNumber"), IsReadOnly = true });
I'd like to update the "Selected" field when the row is selected. I've looked all over and haven't found a good solution. I don't see any events that I can use. Also I'd like for the first row not to be selected automatically when the datagrid is loaded.
msalsbery
Participant
1942 points
358 Posts
06-27-2009 4:50 PM |
I'd like to update the "Selected" field when the row is selected. I've looked all over and haven't found a good solution. I don't see any events that I can use.
Perhaps the DataGrid.SelectionChanged event?
Mark
yifung
Contributor
3313 points
540 Posts
06-28-2009 4:22 PM |
Is Selected a property on your entity, and you have one for each object in your list? If so, make sure your entity implementd INotifyPropertyChanged. Use the SelectionChanged event on the DataGrid as suggested above. When you get the event, loop through e.OldItems and set Selected to false and do the same for e.NewItems but set Selected to true on those. The CheckBoxes in your UI will automatically update since they're databound