Change Datagrid column headers after binding to datatable

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 13 years ago by Bret Naughton
Version: 11.1.0545
Avatar
Hi,

I am displaying a datagrid. But I am having an issue when trying to loop through the datagrid columns afterwards as I want to dynamically change the header for each column. The code is telling me that no columns exist, i.e. DataGrid.Columns.Count = 0, even though I can see the columns & data correctly when run on the screen.

So what I do is

Dim ThemedDataGridVal = New DataGrid.ThemedDataGrid

ThemedDataGridVal.ItemsSource = DataTable.DefaultView

I then add to my grid and everything displays OK.

The reason I need to then change the column headers is that the the datatable I bind to uses uniqueids as the column names - this is because I may have duplicate actual names for columns being displayed.

So what I want to do after the datagrid is connected to the datatable is loop through the datagrid columns and change the header explicitly to the actual required name (I am hoping that I can have duplicate header column names in the datagrid).

It seems that by binding the datatable, I do not have access to the columns. the code I am trying is as follows:

For Each column In ThemedDataGridVal.Columns
MsgBox(column.header.tostring)
Next

Grateful for any ideas.

Thanks,
Bret

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bret,

Our ThemeDataGrid is an extension of the Microsoft DataGrid, and we only support our extensions/themes. General DataGrid questions should be directed to Microsoft or a third-party Q&A site (such as StackOverflow).

I suspect that the automatically generated columns may not be available in that manner though. This question seems to be similar.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.