Select GridColumn Checkbox
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
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
- 1 Reply
- 2 Participants
-
VI vinod
- Apr 5, 2016 11:04 AM UTC
- Apr 6, 2016 11:38 AM UTC