Hi,
I want to collapse rows in XamDataGrid. How this can be done ?
Please help me with this.
Thanks
Arpita
Hello Odosk,
Thank you for your email. I have been looking into your question and if you wish the records of the XamDataGrid to be awlayes expanded, what I can suggest is using the InitializeRecord event of the XamDataGrid and in the event handler to set the e.Record.IsExpanded to true. Also to prevent the records from collapsing, you can handle the RecordCollapsing event and set the e.Cancel to true. I have created a sample application for you that shows how you can implement this.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
I am sorry if this is a stupid question, but I have not been able to do something that must be very easy.
I want to set my grid to be expanded always, so a line of code in my Xaml to set the Recods Expanded property to True is what I need.
Or do I need to set this property after each time I repopulate the grid?
Thanks :)
Hello Arpita,
Thank you for your reply. I have been looking into it and using the code that you have mentioned, you are actually setting the Height of the XamDataGrid itself, though the DataPresenter property. You can use the following method, in order to reset the Height of all DataRecordPresenter in the XamDataGrid:
private void button1_Click_1(object sender, RoutedEventArgs e) { ResetRecordHeight(xamDataGrid1.Records); } public void ResetRecordHeight(RecordCollectionBase recs) { foreach (Record rec in recs) { DataRecordPresenter presenter = DataRecordPresenter.FromRecord(rec) as DataRecordPresenter; if (presenter != null) presenter.Height = double.NaN; if (rec is DataRecord) { if (rec.HasChildren) ResetRecordHeight((rec as DataRecord).ChildRecords); } if (rec is ExpandableFieldRecord) { if (rec.HasChildren) ResetRecordHeight((rec as ExpandableFieldRecord).ChildRecords); } } }
Using this approach, you are iterating all the reocrds in the XamDataGrid and set the Height of their DataRecordPresenter to NanN and this forces the DataRecordPresenter to go to its original Height.
Krasimir
Developer Support Engineer
Krasimir,
Thanks for the solution. The collapse part of it works for me based on the style but the button click to bring back these hidden rows to make them visible does not work. I don't have a boolean field for the same. Is there any other way to specify the height of the records in the grid from code behind? I could do that in the button click event and expand/make the records visible. I tried using this but it didn't work dataGrid.Records.ToList().ForEach((x) => x.DataPresenter.Height = double.NaN);
Thanks,
Thank you for the clarification. I have been reading through your post and if I understand correctly you wish to hide some of the records in the XamDataGrid, based on a condition. To do that I can suggest using a Setter for the Height property of the XamDataGrid and bound it to the property that is you wish to determine whether the record should be visible and using a converter you can set the Height to 0 for collapsed and double.NaN to return the record in view. I have modified the sample application that I have sent you previously in order to demonstrates this. When you uncheck the checkbox in the child records, they disappear and if you press the button, to set all properties to true, the records are back in view. Also you can use a Filtering in order to hide records in the XamDataGrid, based on a condition. You can apply filter in code. You can find an example on how this can be achieved, here in our documentation: http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=xamDataPresenter_Add_Filter_Conditions.html