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.

Passing RowIndex to IValueConverter

Thread ID:

Created:

Updated:

Platform:

Replies:

120390 Sep 20,2015 06:15 AM Sep 24,2015 01:46 AM WPF 3
loading
Tags: SfDataGrid
Michael
Asked On September 20, 2015 06:15 AM

Hi.

Does exist possibility to pass RowIndex from DisplayBinding  to converter?
I can pass DataRowView, but I'd like to pass row index (in grid).

Sincerely,
Michael

Elangovan S [Syncfusion]
Replied On September 21, 2015 10:03 AM

Hi Michael,

Thank you for Contacting Syncfusion Support.

We have analyzed your query.  We cannot pass the row index value directly from DisplayBinding to Converter.  However you can achieve your requirement by passing GridCell element in DisplayBinding and get the RowIndex in Converter.

Code Example for Xaml:


<Syncfusion:SfDataGrid x:Name="datagrid"

                               AllowEditing="True"

                               ShowGroupDropArea="True"

                               ItemsSource="{Binding GDCSource}"

                               AllowSorting="True">

            <Syncfusion:SfDataGrid.Columns>

                <Syncfusion:GridTextColumn MappingName="EmployeeName" />

                <Syncfusion:GridTextColumn MappingName="EmployeeAge" DisplayBinding="{Binding RelativeSource={RelativeSource AncestorType=Syncfusion:GridCell},Converter={StaticResource customvalueconverter}}"  />

                <Syncfusion:GridTextColumn MappingName="EmployeeArea"/>

                <Syncfusion:GridTextColumn  MappingName="EmployeeGender"/>

                <Syncfusion:GridDateTimeColumn MappingName="EmployeeDate"/>

            </Syncfusion:SfDataGrid.Columns>

</Syncfusion:SfDataGrid>


Code Example for C#:


public class CustomValueConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            var gridCell = value as GridCell;

            var columnBase = gridCell.ColumnBase as DataColumn;


            if(columnBase.RowIndex % 2 != 1 )

                return "38";

            return "34";

        }


        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            var gridCell = value as GridCell;

            var columnBase = gridCell.ColumnBase as DataColumn;


            if (columnBase.RowIndex % 2 != 1)

                return "38";

            return "34";

        }

    }


You can download the sample from the following link:

Sample Link:

http://www.syncfusion.com/downloads/support/forum/120390/ze/WpfSample844597472


Please let us know if you have any query.


Regards,

Elangovan S


Michael
Replied On September 23, 2015 07:17 AM

Thank you for example.
Could you give almost the same example, but with data source DataTable.
I set data source by:

datagrid.DataContext = t.DefaultView;

t is DataTable.

Jayaleshwari N [Syncfusion]
Replied On September 24, 2015 01:46 AM

Hi Michael,

Thanks for your update.

We have modified the sample as per your requirement “Sample with items source as DataTable”. You can download the same from the following location.

Sample location: DataTable

Please let us know, if you need further assistance on this.

Regards,

Jayaleshwari N.


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.

;