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
close icon

Passing RowIndex to IValueConverter

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

3 Replies

ES Elangovan S Syncfusion Team September 21, 2015 02:03 PM UTC

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



MI Michael September 23, 2015 11:17 AM UTC

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.


JN Jayaleshwari N Syncfusion Team September 24, 2015 05:46 AM UTC

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.


Loader.
Live Chat Icon For mobile
Up arrow icon