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.
Unfortunately, activation email could not send to your email. Please try again.

Columns header

Thread ID:

Created:

Updated:

Platform:

Replies:

132217 Aug 21,2017 06:51 AM Aug 24,2017 11:01 AM WPF 3
loading
Tags: SfDataGrid
Gianfranco Vrech
Asked On August 21, 2017 09:14 AM

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 09:41 AM

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 
 
 
Regards, 
Balamurugan R 


Gianfranco Vrech
Replied On August 23, 2017 04:40 AM

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 11:01 AM

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. 
 
 
Regards, 
Srinivasan 


CONFIRMATION

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.

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.

;