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. Image for the cookie policy date

Relative binding!

1.Can i binding the row like this?   
<DataGridCheckBoxColumn Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}"  Header="IsSelected" />

2.sometimes i just want bind the row datacontext to a control in templatecolumn with a converter,any idea?

7 Replies

JG Jai Ganesh S Syncfusion Team March 19, 2016 05:27 AM UTC

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


Kb Link: https://www.syncfusion.com/kb/5904/how-to-pass-row-data-as-parameter-to-the-command-in-viewmodel-when-clicking-the-button-in


Regards,

Jai Ganesh S



RA ray March 19, 2016 08:52 AM UTC

I just want bind the row selection status to a checkbox in datagrid.......


RA ray March 21, 2016 02:05 AM UTC

So , there is no easy way to bind the row selection to a DataGridCheckBoxColumn or a checkbox in template column?


SV Srinivasan Vasu Syncfusion Team March 21, 2016 12:51 PM UTC

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



RA ray replied to Srinivasan Vasu March 21, 2016 01:14 PM UTC

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


Maybe we are misunderstanding. In WPF ,the original datagrid can bind the row selection like this .<DataGridCheckBoxColumn Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}"  Header="IsSelected" />  I just want konw any way to do it with sfdatagrid.....


SV Srinivasan Vasu Syncfusion Team March 23, 2016 02:10 AM UTC

Hi  Ray,

Currently we do not have the support for “Binding the row selection status to a GridCheckBoxColumn in SfDataGrid”. Thank you for helping us define this feature. We are working on your requirement “Bind the row selection status to a GridCheckBoxColumn in SfDataGrid”. We will implement this feature in any of our upcoming releases.

Please let us know if you require further assistance on this.

Regards,
Srinivasan



SV Srinivasan Vasu Syncfusion Team March 23, 2016 04:16 AM UTC

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

 


Loader.
Up arrow icon