AutoGeneratingColumn event

Hello.  

I want the user to be able to choose the columns they want displayed so I'm using the ChooseColumnPopup to show the available columns.  I've attached an event to the Ok button and save the selected columns.  Using the AutoGeneratingColumn event to cancel any column not in the selected columns seems to work just fine.  But if I show the ChooseColumnPopup again, the columns I cancelled are not in the list. 

There has to be a better approach to this problem.  Any ideas?

Thank you


4 Replies

DZ David Zangger January 18, 2025 08:53 PM UTC

Of course after I post this, I had an idea.

This is what I was using:

e.Cancel = !(DAC.Configuration.SelectedColumns.Contains($"[{e.Column.MappingName}]"));

So I thought about just making it not visible

e.Column.Visible = DAC.Configuration.SelectedColumns.Contains($"[{e.Column.MappingName}]");

That seemed to have made it work.  Still would be interested if there is a better approach.

Thank you



MS Malini Selvarasu Syncfusion Team January 20, 2025 02:37 PM UTC

Hi David Zangger,

Based on the information provided, we understand that you are displaying the `ColumnChooserPopup` to select items and attempting to display them, while canceling the generation of columns for unselected items in the `AutoGeneratingColumn` event. However, upon reopening the popup, the items are not displayed.
We recommend that, instead of canceling column generation for unselected items, you set the column's visibility to `false` after setting the `ItemsSource`. This approach ensures that unselected items remain hidden in the grid but are preserved in the `ColumnChooser`. Consequently, when you reopen the `ColumnChooserPopup`, the columns are displayed and maintained correctly. Please refer to the code snippet below:
Code Snippet:
sfDataGrid1.DataSource = collections.Orders;
columnChooserPopup = new ColumnChooserPopup(this.sfDataGrid1);
columnChooserPopup.Show();
this.sfDataGrid1.Columns[0].Visible = false;
this.sfDataGrid1.Columns[1].Visible = false;
You can also customize the `ColumnChooser` functionality. Please refer to the following UG documentation for detailed guidance:
Regards,
Malini Selvarasu


DZ David Zangger January 20, 2025 03:37 PM UTC

Hi Malini - Thank you for your response and confirming I need to hide the columns instead of cancelling them.  I appreciate your help!



MS Malini Selvarasu Syncfusion Team January 21, 2025 06:41 AM UTC

Hi David Zangger,

We are glad to hear that your requirement has been fulfilled. Hence, we are closing this forum. Please feel free to reach out to us if you need further assistance. We are always happy to help.
Regards,
Malini Selvarasu

Loader.
Up arrow icon