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.
Unfortunately, activation email could not send to your email. Please try again.

Relative binding!

Thread ID:

Created:

Updated:

Platform:

Replies:

123436 Mar 17,2016 05:58 AM Mar 23,2016 12:16 AM WPF 7
loading
Tags: SfDataGrid
ray
Asked On March 17, 2016 05:58 AM

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?

Jai Ganesh S [Syncfusion]
Replied On March 19, 2016 01:27 AM

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


ray
Replied On March 19, 2016 04:52 AM

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

ray
Replied On March 20, 2016 10:05 PM

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

Srinivasan Vasu [Syncfusion]
Replied On March 21, 2016 08:51 AM

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


ray
Replied On March 21, 2016 09:14 AM

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.....

Srinivasan Vasu [Syncfusion]
Replied On March 22, 2016 10:10 PM

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


Srinivasan Vasu [Syncfusion]
Replied On March 23, 2016 12:16 AM

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

 


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.

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.

;