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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Columns header

Thread ID:





132217 Aug 21,2017 10:51 AM UTC Aug 24,2017 03:01 PM UTC WPF 3
Tags: SfDataGrid
Gianfranco Vrech
Asked On August 21, 2017 01:14 PM UTC

I'm trying to use your SfDataGrid control.
My scenario is a textbox where the user inserts a value the SfDataGrid in binding with a Datatable.
<Syncfusion:SfDataGrid x:Name= "Data" AutoGenerateColumns="True"  ItemsSource="{Binding BomDelseDataTable}"  />
In the guide it is written that the control supports binding with the datatable, but when I modify the header, no changes appends.

When the textbox loses focus, I would like to update the SfDataGrid control with the new value of the colum header.
BomDelsDataTable.Columns.Item(OldNameColHeader).ColumnName = NewNameColHeader
I need to do this in Runtime after I've created it.

I use VB.net, WPF and MVVM.

Balamurugan Rajaraman [Syncfusion]
Replied On August 22, 2017 01:41 PM UTC

HI Gianfranco Vrech, 
Thanks for contacting Syncfusion support. 
We have checked your query “How to change the header name at runtime”. You can able to change the column header at runtime by using HeaderText property of the GridColumn as like the below provided code snippet. 
Public Sub AddNewRecord(obj As Object) 
    TryCast(DirectCast(obj, Object())(1), SfDataGrid).Columns(0).HeaderText = DirectCast(DirectCast(obj, Object())(0), System.Windows.Controls.TextBox).Text 
End Sub 
Another way using the ColumnName instead of index 
Me.datagrid.Columns("EmployeeID").HeaderText = "NewColumnName" 
We have created the sample based upon your requirement and attached that sample for your reference you can able to get it from the below link 
Balamurugan R 

Gianfranco Vrech
Replied On August 23, 2017 08:40 AM UTC

Ok, I tryed your solution and works fine, but in my scenario, I need to work with the datatable and not with the control.

So there's a way to force the new datatable content to view? I've more than one property to set...

Srinivasan Vasu [Syncfusion]
Replied On August 24, 2017 03:01 PM UTC

Hi Gianfranco Vrech, 
We have checked your query and we have prepared a sample as per your requirement. While changing the DataColumn.ColumnName in DataTable, it will not be reflected in view, because SfDataGrid could not get any notification from DataTable Column property changed since DataTable doesn’t support INotifyPropertyChanged.  
So, we may have to re-create all column when changing the ColumnName. Instead of which, we can remove the old column and add new column based on ColumnName of DataColumn. 
Please refer the below example. 
  Public Sub AddNewRecord(obj As Object) 
        ' (((object[])obj)[1] as SfDataGrid).Columns[0].HeaderText = ((System.Windows.Controls.TextBox)((object[])obj)[0]).Text; 
        Dim previousColumnName As String = TryCast(TryCast(DirectCast(obj, Object())(1), SfDataGrid).DataContext, DataTableClass).EmployeeDetails.Columns(2).ColumnName 
        ' Change ColumnName of Name column in DataTableCollection 
        TryCast(TryCast(DirectCast(obj, Object())(1), SfDataGrid).DataContext, DataTableClass).EmployeeDetails.Columns(2).ColumnName = DirectCast(DirectCast(obj, Object())(0), System.Windows.Controls.TextBox).Text 
        Dim mappingName As String = TryCast(TryCast(DirectCast(obj, Object())(1), SfDataGrid).DataContext, DataTableClass).EmployeeDetails.Columns(2).ColumnName 
        Dim column = TryCast(DirectCast(obj, Object())(1), SfDataGrid).Columns.FirstOrDefault(Function(x) x.MappingName = previousColumnName) 
        ' Remove column based on MappingName from GridColumns 
        TryCast(DirectCast(obj, Object())(1), SfDataGrid).Columns.Remove(TryCast(column, GridColumn)) 
        ' Insert a column based on MappingName with GridColumns 
        TryCast(DirectCast(obj, Object())(1), SfDataGrid).Columns.Insert(2, New GridTextColumn() With { 
        .MappingName = mappingName 
    End Sub 
Also, please ensure that we have understood your query and your requirement is to change ColumnName? If your requirement is to change the caption or may be different from what we have understood, please revert us with more details. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon