I want to copy all the datagrid records into datatable without using any loop. For Ex:
Dim dt as New DataTable
dt = Datagrid1.Items
But this is not Working and giving an error message.
My Development platform is Visual studio 2010 and language is WPF with vb.net 4.0
To convert your dataGrid into data table whith header row you can follow this steps:
1) create the method to retrive the cell
2) Iterate through all items and pass the content to dada table "cell"
Keep in mind to use this methods you must will reference this using:
You have to loop on DataGrid and add item to Datatable. below link may help.
DataGridView selected rows to DataTable
It depends how the datagrid is populated. If the DataContext property is set to a DataTable then you can simply just retrieve this value and cast to a DataTable.
There is no direct method to convert this to a DataTable from the DataGrid element.
If you wanted to do this manually, you would have to create an instance of the DataTable, then create the rows from the Items in the DataGrid using a loop.
This is the way to transfer all the records from DATAGRID to DATATABLE without using the LOOP.
VB:
C#:
i just tested this and this works