Hi,
When using the xamdatagrid field chooser, The datagrid is getting refreshed for each change in the chooser window. But I want to refresh the grid only after closing the field chooser window with multiple selected or deslected fields. Please help on this. I am using 2013.2 version.
Thanks,
Sreek
Hello Sreek,
I have investigated the custom FieldChooser functionality you are trying to achieve with explicit binding and I recommend you to set the e.Cancel to true in the FieldChooserOpening event and put up your custom dialog instead of re-templating the FieldChooser. Having the custom dialog will allow you to control the look and the behavior of the element. I have modified the attached sample application in order to show you how can create custom FieldChooser with the functionality you want.
Basically I have added EntryModel class which contains properties for field name, isvisible and category. In the Grid I have added our XamDialogWindow with XamDataGrid that has similar fields and setting like in your application, so in the FieldChooserOpening I canceled the default FieldChooser window and open our XamDialogWindow. I created ObservableCollection<EntryModel> FChooserEntry, in order to get the fields, their visibility and category. Then I set the XamDataGrid’s DataContext to be FChooserEntry collection and also handle the WindowStateChanged event of dialog window. This way we can check and uncheck the fields and then when we close the dialog we may iterate through the Fields from main grid and set Visibility to be equal to the corresponding property from FChooserEntry collection, for example:
<ig:XamDialogWindow WindowState="Hidden" Name="dialog" Width="350" Height="300" IsModal="False" StartupPosition="Center" > <ig:XamDialogWindow.Content> <igDP:XamDataGrid Name="xdgInChooser" DataSource="{Binding}" > <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowRecordFiltering="true"/> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:CheckBoxField Name="IsVisible"> <igDP:CheckBoxField.Settings> <igDP:FieldSettings CellMaxWidth="100" AllowEdit="true" > </igDP:FieldSettings> </igDP:CheckBoxField.Settings> </igDP:CheckBoxField> <igDP:Field Name="Category"> <igDP:Field.Settings> <igDP:FieldSettings CollapseWhenEmpty="True" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> <igDP:FieldLayout.SortedFields> <igDP:FieldSortDescription FieldName="Category" Direction="Ascending" IsGroupBy="True"/> </igDP:FieldLayout.SortedFields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </ig:XamDialogWindow.Content> </ig:XamDialogWindow>
private void xdg_FieldChooserOpening(object sender, Infragistics.Windows.DataPresenter.Events.FieldChooserOpeningEventArgs e){ FChooserEntry = new ObservableCollection<EntryModel>(); e.Cancel = true; foreach (var entry in xdg.FieldLayouts[0].Fields) { FChooserEntry.Add(new EntryModel() { FName = entry.Name.ToString(), IsVisible = (entry.Visibility == Visibility.Visible) ? true : false , Category = entry.Tag.ToString() }); } xdgInChooser.DataContext = FChooserEntry; dialog.WindowState = Infragistics.Controls.Interactions.WindowState.Normal; dialog.WindowStateChanged += Dialog_WindowStateChanged;}
foreach (var entry in xdg.FieldLayouts[0].Fields) { FChooserEntry.Add(new EntryModel() { FName = entry.Name.ToString(), IsVisible = (entry.Visibility == Visibility.Visible) ? true : false , Category = entry.Tag.ToString() }); } xdgInChooser.DataContext = FChooserEntry; dialog.WindowState = Infragistics.Controls.Interactions.WindowState.Normal; dialog.WindowStateChanged += Dialog_WindowStateChanged;}
private void Dialog_WindowStateChanged(object sender, Infragistics.Controls.Interactions.WindowStateChangedEventArgs e){ if (e.NewWindowState == Infragistics.Controls.Interactions.WindowState.Hidden) { int i = xdg.FieldLayouts[0].Fields.Count - 1; while (i >= 0) { switch (FChooserEntry[i].IsVisible) { case false: xdg.FieldLayouts[0].Fields[i].Visibility = Visibility.Collapsed; i--; break; default: xdg.FieldLayouts[0].Fields[i].Visibility = Visibility.Visible; i--; break; } } }}
} }}
Also if you would like an option for ‘delayed apply’ to be added in FieldChooser for the future versions you can add a new Product Idea. You can suggest new product ideas for future versions (or vote for existing ones) at http://ideas.infragistics.com . Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. You can also link back to this thread for additional details.
Please let me know if you require any further assistance on this matter.
Sincerely, ZhivkoEntry Level Software Developer
Awaiting for your response... As this feature is very important for our users, your quick response on this would helps us alot...
Thanks
Hi Zhivko - Can you respond on this please...?
Thank you Zhivko.
When set the RecordContainerGenerationMode to PreLoad, then I am able to get all the checkboxes. great.
But, now another issue I found is that, when I select a field and expand another group (to select other field), then the first field's ischecked status is set back to old value. Please run the attached sample to see the behavior. This problem occurs not only on expanding groups, but also while scrolling, and filtering. that means whenever the ui is refreshed, the bindings are recreated, so check boxes gets value from its source isVisible (the IsVisible property on the data item still holds the previous value because the property change is not yet triggered).
Our users will definitely get annoyed by this behavior. Can you help us with a user friendly behavior here please...?
Thanks.
I was able to reproduce your behavior and I can say that this is the designed behavior caused by the Recycle mode of virtualization in XamDataGrid.
The virtualization is a feature which highly improve the performance in the application if you are loading a large number of records at a time. The idea behind virtualization is that only the visible rows are rendered in the grid, and these rendered records are used later as a container for the generated data. As users start to scroll the grid data in the pool of rows is updated and the records elements are reused.
In your scenario once you expand the record the child DataRecordPresenters are created and when collapse it, they are cached with purpose of better performance(they are in the visual tree, but not visible). Additional details about caching, reusing elements and performance optimizations are available here. Additional details about different modes of virtualization you can find here.
The record virtualization (which is when you are scrolling vertically) is controlled by the RecordContainerGenerationMode property of the XamDataGrid. You can turn off the virtualization of your XamDataGrid located in FieldChooser window by setting it to PreLoad. This way the DataRecordPresenters(and XamCheckEditors) will be generated when the XamDataGrid loads and would not be virtualized. Please note the PreLoad setting is appropriate for scenarios where you have a relatively small number of rows or columns (when setting CellContainerGenerationMode), otherwise the loading time and memory footprint can become noticeable.
Please let me know if you require any further assistance regarding this matter.