We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the checkbox in the sfdatagrid header to on after initial loading?

Thread ID:

Created:

Updated:

Platform:

Replies:

141254 Dec 2,2018 07:41 PM UTC Dec 10,2018 04:52 AM UTC WPF 6
loading
Tags: SfDataGrid
Allan
Asked On December 2, 2018 07:41 PM UTC

Hi

I'm creating a list of files that can be selected in a sfdatagrid using the sample from

https://www.syncfusion.com/forums/125104/how-to-do-checkbox-in-sfdatagrid-header-or-group-header

I wish to extend this sample so that all rows are initially selected and the checkbox is in the header is also selected after the sfdatagrid is loaded with data. 

I've been able to set all the checkboxes on from the viewmodel, however I haven't had any luck getting the sfdatagrid.selectall() to work so that the rows are selected and highlighted after the data is loaded. I've tried adding code to the sfdatagrid  loaded event without success.

Can you please point me in the right direction?
thanks
Allan



Deivaselvan Y [Syncfusion]
Replied On December 3, 2018 09:45 AM UTC

Hi Allan,

Thank you for contacting Syncfusion support.

You can achieve your requirement by invoking the SelectAll method in Loaded event of SfDataGrid and override the SelectAll method of GridSelectionController to set value to the Checkbox. Please refer the below sample to meet your requirement to set Checked state to the Checkbox and select all the rows in the DataGrid during initial loading. Try running this sample and let us know if this helps you.
http://www.syncfusion.com/downloads/support/forum/141254/ze/SFDATA~156213210.zip

Regards,
Deivaselvan 


Allan
Replied On December 3, 2018 05:15 PM UTC

HI Deivaselvan 

Thanks for your reply. I downloaded and ran your sample and then implemented similar logic in my code.
My situation is complicated by an asynchronous data load in the view model. This is being trigger by a window interaction trigger

  <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding ViewLoaded}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

which fires an asynchronous data load of the sfdatagrid. When it hits the await statement, the control is released to the datagrid code behind event which initiaties the SelectAll(). Unfortunately the viewmodel hasn't finished loading the data at this point so the RowSelectionDocsController does not have a complete data set. I can get past this problem by forcing the data load to be synchronous however I was hoping to keep the data access asynchronous.

Is it possible to prevent the event in your example from firing until the data load in the view model has completed?

  private void Datagrid_Loaded(object sender, RoutedEventArgs e)
        {
            this.datagrid.SelectAll();
        }

Regards
Allan

Deivaselvan Y [Syncfusion]
Replied On December 7, 2018 05:34 AM UTC

Hi Allan,

Thanks for the update.

Kindly share your code implementation on how you are populating the data in ViewModel asynchronously and this may help us to mimic the same at our end to investigate further on this and provide you the appropriate solution at the earliest.

Regards,
Deivaselvan 


Deivaselvan Y [Syncfusion]
Replied On December 7, 2018 10:47 AM UTC

Hi Allan,

We have also suspect you may set ItemsSource of the DataGrid asynchronously after loaded the DataGrid control. If this is your case, then you may invoke SelectAll method within the ItemsSourceChanged event of DataGrid as like below code example. 
this.DataGrid.ItemsSourceChanged += DataGrid_ItemsSourceChanged; 
 
private void DataGrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e) 
{ 
    this.DataGrid.SelectAll(); 
} 

If still your requirement is not meet with any of our proposed solution, then kindly provide the details as we requested earlier such as asynchronous code implementation of Data population in ViewModel and how it was bind with the DataGrid. Thereby we could analyze further and update you with the appropriate solution at the earliest.

Regards,
Deivaselvan 


Allan
Replied On December 7, 2018 05:23 PM UTC

Hi Deivaselvan

Your last suggestion to use the itemssourcechanged event has fixed my problem.

I have the itemssource attached to an observable collection that is being loaded asynchronously via the interaction trigger.

Thank you for your help.
Regards
Allan

Deivaselvan Y [Syncfusion]
Replied On December 10, 2018 04:52 AM UTC

Hi Allan,

Thanks for the update.

We are glad to know that your issue has been fixed by handling ItemsSourceChanged event. Please let us know if you need any further assistance.

Regards,
Deivaselvan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;