Hi Michael, Your understanding is pretty spot on. You basically need a way for the underlying data to say to the bound control "Hey, my data's changed, you should consider checking to see if you need to update your display" and that's exactly what INotifyPropertyChanged does. This is what most binding in controls in WPF works. Cheers, Justin Taylor Readify | Senior Developer M: +61 418 615 956 | E: [email protected]<mailto:[email protected]> | B: http://blog.jtango.net<http://blog.jtango.net/>
From: [email protected] [mailto:[email protected]] On Behalf Of King, Michael Sent: Wednesday, 19 January 2011 12:07 PM To: ozWPF Subject: RE: Problem with checkbox column in DataGrid Ahhh..... no it does not. As the penny starts to drop. Now, I am struggling a bit with the MVVM concept. The Part class I am treating as my Model so I didn't think it was needed there. I thought the INotifyPropertyChanged functionality should be in my ViewModel (but in this case I don't have it there either), so you may have very quickly discovered my error. The DataGrid seems to be a little different to the other controls I have used so far - Is this how it works? To change the display of the DataGrid, I change the properties of the underlying ItemsSource and , provided I have the INotifyPropertyChanged stuff implemented, then the DataGrid will display the changes? Cheers, Michael King From: [email protected] [mailto:[email protected]] On Behalf Of Justin Taylor Sent: Wednesday, 19 January 2011 11:47 AM To: ozWPF Subject: RE: Problem with checkbox column in DataGrid Hi Michael, Does your Part class implement INotifyPropertyChanged and raise a PropertyChanged event in the setter for the "Selected" property? Cheers, Justin Taylor Readify | Senior Developer M: +61 418 615 956 | E: [email protected]<mailto:[email protected]> | B: http://blog.jtango.net<http://blog.jtango.net/> From: [email protected] [mailto:[email protected]] On Behalf Of King, Michael Sent: Wednesday, 19 January 2011 11:31 AM To: [email protected] Subject: Problem with checkbox column in DataGrid Hi all, I am having problems with what I thought would be a pretty simple task. I have a DataGrid which includes a CheckBox column. I am populating this dynamically as follows: dg.AutoGenerateColumns = false; List<Part> prts = new List<Part>(); prts = Parts.GetPartsFromDbNotInMgo(); dg.ItemsSource = prts; dataGridRowCount = prts.Count; DataGridCheckBoxColumn chkColumn = new DataGridCheckBoxColumn(); chkColumn.Header = "Delete"; chkColumn.Binding = new Binding("Selected"); dg.Columns.Add(chkColumn); DataGridTextColumn prtNumColumn = new DataGridTextColumn(); prtNumColumn.Header = "Part Number"; prtNumColumn.Binding = new Binding("PartNumber"); dg.Columns.Add(prtNumColumn); DataGridTextColumn prtDescColumn = new DataGridTextColumn(); prtDescColumn.Header = "Desc"; prtDescColumn.Binding = new Binding("PartDesc"); dg.Columns.Add(prtDescColumn); DataGridTextColumn prtSuppColumn = new DataGridTextColumn(); prtSuppColumn.Header = "Supplier"; prtSuppColumn.Binding = new Binding("Supplier"); dg.Columns.Add(prtSuppColumn); DataGridTextColumn prtCmntColumn = new DataGridTextColumn(); prtCmntColumn.Header = "Comment"; prtCmntColumn.Binding = new Binding("Comment"); dg.Columns.Add(prtCmntColumn); I tried using a DataSet as the source for the DataGrid but couldn't get that working either.... Now I have two issues - I want a way to check/uncheck all the checkboxes in the column - using a "select all" button or similar And I need a way to cycle through the DataGrid and select only the checked records for further action. These probably will be very similar. I tried setting the underlying values: foreach (Part pt in dg.ItemsSource) { pt.Selected = chk; } And: for (int x = 0; x < dataGridRowCount; x++) { ((Part)dg.Items[x]).Selected = chk; } But this does not affect the actual checkboxes. I have searched the web for hours and found lots of Web-based solutions but cannot get anything that works here. Can anyone point me in the right direction? MICHAEL KING
_______________________________________________ ozwpf mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
