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

How to display RowIndex at RowHeaderCell in SfDataGrid

Using Xamarin Forms, how to display RowIndex at RowHeaderCell in SfDataGrid programmatically.

Thanks

1 Reply

SK Shivagurunathan Kamalakannan Syncfusion Team September 9, 2019 11:56 AM UTC

Hi Abhishek,   
    
Thank you for contacting Syncfusion support.   
    
Your requirement “To show the row index in the row header cell programmatically” can be achieved by using RowHeaderTemplate in SfDataGrid.    
    
Please refer the below code.    
    
public partial class MainPage : ContentPage   
{   
              SfDataGrid dataGrid;   
              ViewModel viewModel;   
              public MainPage()   
              {   
                             InitializeComponent();   
                             dataGrid = new SfDataGrid();   
                             viewModel = new ViewModel();   
                             this.BindingContext = viewModel;   
                             dataGrid.ColumnSizer = ColumnSizer.Star;   
                             dataGrid.ItemsSource = viewModel.OrdersInfo;   
                             dataGrid.ShowRowHeader = true;   
                             dataGrid.AutoGeneratingColumn += DataGrid_AutoGeneratingColumn;   
                             dataGrid.RowHeaderTemplate = new DataTemplate(() =>   
                             {   
                                           var label = new Label();   
                                           label.SetBinding(Label.TextProperty, new Binding("Index", BindingMode.Default, null, null, null, null));   
                                           return label;   
                             });   
                             this.Content = dataGrid;   
              }   
              private void DataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnEventArgs e)   
              {   
                             if (e.Column.MappingName == "Index")   
                                           e.Cancel = true;   
              }   
}                
                 
 
  
Please refer the following KB for more details. 
    
We have prepared a sample based on your requirement and it can be downloaded from the below link.   
   
Regards,   
Shivagurunathan   


Loader.
Live Chat Icon For mobile
Up arrow icon