Rename column headers in the sfdatagrid which had been bound to a datatable

The Details of my request are in the attached document.

Kind Regards.

Alain.

Attachment: Rename_Column_names_86ae2710.7z

The code I have used is as follows:

customerDataGrid.Columns(1).HeaderText = "First Name" and I get the following message

'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team August 25, 2020 02:18 AM UTC

Hi Alain,

Thank you for contacting Syncfusion support.

 
Based on provided information we suspect that your set the HeaderText property of GridColumn set before adding column in your application. You can resolve the issue by HeaderText property of GridColumn set after the adding column in your application. Please refer the below code snippet,

 
Dim gridTextColumn1 As New GridTextColumn() With {.MappingName = "OrderID"} 
Dim gridTextColumn2 As New GridTextColumn() With {.MappingName = "CustomerID"} 
 
'Define the header text when column defined 
Dim gridTextColumn3 As New GridTextColumn() With {.MappingName = "CustomerName", 
                                                .HeaderText = "Customer Name"} 
Dim gridTextColumn4 As New GridTextColumn() With {.MappingName = "Country", 
                                                .HeaderText = "Country"} 
Dim gridTextColumn5 As New GridTextColumn() With {.MappingName = "ShipCity", 
                                                .HeaderText = "Ship City"} 
Dim checkBoxColumn As New GridCheckBoxColumn() With {.MappingName = "IsShipped", 
                                                .HeaderText = "Is Shipped"} 
 
sfDataGrid.Columns.Add(gridTextColumn1) 
sfDataGrid.Columns.Add(gridTextColumn2) 
sfDataGrid.Columns.Add(gridTextColumn3) 
sfDataGrid.Columns.Add(gridTextColumn4) 
sfDataGrid.Columns.Add(gridTextColumn5) 
sfDataGrid.Columns.Add(checkBoxColumn) 
 
'Change the Header text of column after column added based on your requirement 
sfDataGrid.Columns(0).HeaderText = "Order ID" 
sfDataGrid.Columns(1).HeaderText = "Customer ID"

 

Sample Link: https://www.syncfusion.com/downloads/support/forum/157184/ze/RenameColumnHeaderText-280180109

We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon