Prabhagaran P February 2016

How to insert data into datatable from datagrid without using ItemSource in Wpf?

I have a Datagrid which has DataView as ItemSource . Actually that DataGrid will not display all data which is in Dataview. i.e if dataview has 21 column but datagrid displayed only 13 column.Now i want to select those 13 columns and add it to New DataTable. I dont know how to do this. Please help me. Thankyou

Answers


Tim Schmelter February 2016

You can use DataView.ToTable:

C#:

string[] columnNames = { " Col1", "Col2", "...", "Col13" };
DataTable newTable = view.ToTable("TableName", false, columnNames);

VB.NET:

Dim columnNames = { " Col1", "Col2", "...", "Col13" }
Dim newTable As DataTable = view.ToTable("TableName", False, columnNames)

Post Status

Asked in February 2016
Viewed 2,674 times
Voted 14
Answered 1 times

Search




Leave an answer