Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
146023 | Jul 17,2019 10:16 AM UTC | Nov 27,2019 05:30 AM UTC | WPF | 13 |
![]() |
Tags: SfDataGrid |
protected override void ProcessKeyDown(KeyEventArgs args)
{
if (Keyboard.IsKeyDown(Key.A) && SelectionHelper.CheckControlKeyPressed())
{
this.DataGrid.SelectionController.ClearSelections(false);
this.DataGrid.SelectRows(1, this.DataGrid.GetLastDataRowIndex());
var collectioncount = (DataGrid.DataContext as ViewModel).OrderInfoCollection.Count;
var selecteditemcount = DataGrid.SelectedItems.Count;
if (selecteditemcount == collectioncount)
(this.DataGrid.DataContext as ViewModel).IsHeaderChecked = true;
else if (selecteditemcount == 0)
(this.DataGrid.DataContext as ViewModel).IsHeaderChecked = false;
else
(this.DataGrid.DataContext as ViewModel).IsHeaderChecked = null;
foreach (var collection in (DataGrid.DataContext as ViewModel).OrderInfoCollection)
{
if (collection.IsChecked == false)
collection.IsChecked = true;
}
return;
}
base.ProcessKeyDown(args); // Base method calling
}
|
private void AssociatedObject_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
if (((e.OriginalSender as SfDataGrid).DataContext as ViewModel).IsHeaderChecked == true)
{
SfDataGrid dataGrid = e.OriginalSender as SfDataGrid;
if(dataGrid.SelectionMode==GridSelectionMode.Multiple)
{
if (e.RemovedItems != null && e.RemovedItems.Count > 0)
{
var items = e.RemovedItems;
var rowInfo = items[0] as GridRowInfo;
var rowData = rowInfo.RowData as OrderInfo;
rowData.IsChecked = true;
dataGrid.SelectedIndex = dataGrid.ResolveToRecordIndex(rowInfo.RowIndex);
}
}
else if(dataGrid.SelectionMode==GridSelectionMode.Extended)
{
if (e.AddedItems != null && e.AddedItems.Count > 0)
{
var items = e.AddedItems;
var rowInfo = items[0] as GridRowInfo;
var rowData = rowInfo.RowData as OrderInfo;
rowData.IsChecked = true;
dataGrid.SelectedIndex = dataGrid.ResolveToRecordIndex(rowInfo.RowIndex);
}
}
}
} |
<syncfusion:SfDataGrid x:Name="dataGrid" AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridCheckBoxSelectorColumn MappingName="SelectorColumn" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid> |
this.dataGrid.Columns.Add(new GridCheckBoxSelectorColumn()
{
MappingName = "SelectorColumn"
}); |
Hi,
this is exactly what I needed.
But there is one problem with that. Once row is selected I cannot deselect it by clicking on the checkbox in GridCheckBoxSelectorColumn. It seems like a bug. It's not working with extended selection mode, but with multiple selection mode it works fine.
Please check.
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.
This page will automatically be redirected to the sign-in page in 10 seconds.