Deactivating MasterDetail View in Runtime

Dear Support

How can I deactivate the MasterDetail View in Runtime. Activating works fine, but on deactivating, the Relations are still there and shown in the Datagrid with a plus...


void ToggleMasterDetailView(object sender, RoutedEventArgs e)
{
//BUG: Deactivating Master Detail View does not work

var tmpItemSource = MainDataGrid.ItemsSource;
MainDataGrid.ItemsSource = null;
MainDataGrid.AutoGenerateRelations = !MainDataGrid.AutoGenerateRelations;
MainDataGrid.ItemsSource = tmpItemSource;
}

3 Replies

VS Vijayarasan Sivanandham Syncfusion Team July 12, 2021 05:09 PM UTC

Hi Patrick,

Thank you for contacting Syncfusion Support.

Your requirement can be achieved by setting null value for DetailsViewDefinition property in SfDataGrid. Please refer the below code snippet, 
private void btnItemSource_Click(object sender, RoutedEventArgs e) 
{ 
            var tmpItemSource = dataGrid.ItemsSource; 
            dataGrid.ItemsSource = null; 
            dataGrid.AutoGenerateRelations = !dataGrid.AutoGenerateRelations; 
            dataGrid.ItemsSource = tmpItemSource; 
            
            //set null value for the child DataGrid 
            dataGrid.DetailsViewDefinition = null; 
}       
 
Please let us know if you have any concerns in this.

Regards,
Vijayarasan S
 



PA Patrick July 12, 2021 05:19 PM UTC

Hi Vijayarasan


Gives me an errer on Toggle back to the AutoGenerateRelations=True.


"An Element with the same key was already added"


br Patrick



VS Vijayarasan Sivanandham Syncfusion Team July 13, 2021 03:06 PM UTC

Hi Patrick,

Thanks for the update.

Provided details are insufficient to find the exact cause for the issue. Can you please provide the more information related to your query?

Can you please share us below things?
1. Provide code snippet related to customization in SfDataGrid
2. Provide the stack trace details of the exception occurred in your application.
3. If possible, kindly provide a simple issue reproducible Sample
4. Provide replication procedure with video illustration of the reported issue

It will be helpful for us to check on it and provide you the solution at the earliest.

Regards,
Vijayarasan S



Loader.
Up arrow icon