Passing RowIndex to IValueConverter
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
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
Could you give almost the same example, but with data source DataTable.
I set data source by:
datagrid.DataContext = t.DefaultView;
t is DataTable.
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.
- 3 Replies
- 3 Participants
-
MI Michael
- Sep 20, 2015 10:15 AM UTC
- Sep 24, 2015 05:46 AM UTC