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

Select GridColumn Checkbox

Thread ID:

Created:

Updated:

Platform:

Replies:

123626 Apr 5,2016 11:04 AM UTC Apr 6,2016 11:38 AM UTC WPF 1
loading
Tags: SfDataGrid
vinod
Asked On April 5, 2016 11:04 AM UTC

Hi Support team,



 I'm trying this Sf:Datagrid  when i check in a particular column need to get the adjacent column name of a row.

Example : When i checked first row get the person name as Maria Anders

Can you suggest me how to achieve this in Sf:Datagrid

Added my sample code below, 

<syncfusion:SfDataGrid x:Name="sfdatagrid"                             
                               ItemsSource="{Binding OrderInfoCollection,
                                                     Source={StaticResource data}}"                             
                                ShowGroupDropArea="True"
                                ShowRowHeader="True"
                                AutoExpandGroups="True"
                                AutoGenerateColumns="False"
                                AllowGrouping="True"
                                AllowEditing="True"                                             
                                ColumnSizer="Star"
                                LiveDataUpdateMode="AllowSummaryUpdate"                                  
                                SelectionMode="Extended"    
                                NavigationMode="Cell"
                                ShowColumnWhenGrouped="True" CurrentCellActivated="sfdatagrid_CurrentCellActivated">    
            <syncfusion:SfDataGrid.Columns>
                <syncfusion:GridCheckBoxColumn  MappingName="IsChecked" />
                <syncfusion:GridTextColumn MappingName="PersonName"/>
            </syncfusion:SfDataGrid.Columns>
        </syncfusion:SfDataGrid>


private void sfdatagrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args)
        {
           

            if(sfdatagrid.View.Records.Count >0)
            {
                foreach (var record in sfdatagrid.View.Records)
                {
                    var data = record.Data as Person;
                    if (data.IsChecked)
                    {
                        savedNames.Add(data.PersonName);
                    }
                }
            }
            CheckedItems.ItemsSource = savedNames;
        }

Thanks
Vinod

Jayapradha S [Syncfusion]
Replied On April 6, 2016 11:38 AM UTC

Hi Vinod,

Thank you for contacting Syncfusion Support.


We have analyzed your query. You can achieve your requirement that you can get the adjacent column values (Eg: EmployeeName) when you checked the checkbox by using RecordPropertyChangedEvent.

Code Example:

this.datagrid.ItemsSourceChanged += datagrid_ItemsSourceChanged; 

void datagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)

{

if(datagrid.View!=null)

this.datagrid.View.RecordPropertyChanged += View_RecordPropertyChanged;

}

void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e)

{

var model = sender as BusinessObjects;

var viewModel = this.datagrid.DataContext as ViewModel;


if(e.PropertyName=="IsChecked")

{

if (model.IsChecked)

viewModel.CheckedItems.Add(model.EmployeeName.ToString());

  else

                    viewModel.CheckedItems.Remove(model.EmployeeName.ToString());

            }
        }


You can achieve the same requirement by using CurrentCellValueChangedEvent also. Find the code example below,

Code Example:
this.datagrid.CurrentCellValueChanged += datagrid_CurrentCellValueChanged;

void datagrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs args)

{

var viewModel=this.datagrid.DataContext as ViewModel;

if ((args.Record as BusinessObjects).IsChecked)

viewModel.CheckedItems.Add((args.Record as BusinessObjects).EmployeeName);               
}



We have prepared a sample for your requirement. Hereby, we have displayed the checked items in the listbox as shown in your image.

Please find the sample from the following location,

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/154774/ze/SfGridSample-294501659.zip


Regards,

Jayapradha


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.

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

;