Hi Ray,
Query 1:
You cannot bind the DataRow in GridCheckBoxColumn through XAML binding. However you can achieve your requirement for selecting the row based on the GridCheckBoxColumn by overriding the GridCheckBoxColumn renderer and customize the Selection Controller like below,
this.sfDataGrid.CellRenderers.Remove("CheckBox"); this.sfDataGrid.CellRenderers.Add("CheckBox", new CheckBoxSelection());
public static class CheckBoxHelper { public static bool IsChecked { get; set; } public static bool Value { get; set; } }
public class CheckBoxSelection:GridCellCheckBoxRenderer { public CheckBoxSelection():base() { } protected override void OnWireEditUIElement(CheckBox uiElement) { base.OnWireEditUIElement(uiElement); uiElement.GotFocus += uiElement_GotFocus; uiElement.LostFocus += uiElement_LostFocus; }
void uiElement_LostFocus(object sender, RoutedEventArgs e) { CheckBoxHelper.IsChecked = false; }
void uiElement_GotFocus(object sender, RoutedEventArgs e) { CheckBoxHelper.IsChecked = true; CheckBoxHelper.Value = !(bool)((CheckBox)e.OriginalSource).IsChecked; } }
public class RowSelectionController:GridSelectionController { public RowSelectionController(SfDataGrid dataGrid):base(dataGrid) { }
protected override void ProcessPointerReleased(MouseButtonEventArgs args, RowColumnIndex rowColumnIndex) { if (!CheckBoxHelper.IsChecked || rowColumnIndex.ColumnIndex != 2) return; base.ProcessPointerReleased(args, rowColumnIndex); } } |
Sample: http://www.syncfusion.com/downloads/support/directtrac/153447/ze/CheckBox1270342973
Query 2:
You can bind the row data in converter inside the DataTemplateColumn like below,
<Syncfusion:GridTemplateColumn MappingName="EmployeeArea" Syncfusion:FocusManagerHelper.WantsKeyInput="True"> <Syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=., Converter={StaticResource converter}}"/> </DataTemplate> </Syncfusion:GridTemplateColumn.CellTemplate> </Syncfusion:GridTemplateColumn>
public class CustomConverter:IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var rowdata = value as BusinessObjects; return rowdata.EmployeeArea; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return 0; } } |
Sample: http://www.syncfusion.com/downloads/support/directtrac/153447/ze/SfDataGridDemo1356490997
Regards,
Jai Ganesh S
Hi Ray,
We have analyzed your query and it is not possible to bind the row selection status to a CheckBox Column in SfDataGrid. Because each row we have bound to underlying business object, which is the behavior of SfDataGrid.
Please let us know further assistance on this.
Regards,
Srinivasan
Hi Ray,
Please ignore our previous update.
We have considered this “Binding the row selection status to a GridCheckBoxColumn in SfDataGrid” as a feature and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents/
Regards,
Srinivasan