Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Datagrid is bound to datatable. But it displays an extra column. I want to delete that column.
when i am trying to get the content of datagrid in datatable I am Getting an Error as "cannot convert type System.windows.Controls.Datagrid to System.Data.Datatable" when i try to get the content of Datagrid into a datatable.


What is the correct way to do it?

My Code: DataTable dataTable = (DataTable)dataGrid;
Posted

The code you posted is trying to create a DataTable from your DataGrid. This is not possible unless you do something like

C#
DataTable dt = (DataTable)dataGrid.DataContext;


but even still this does not really compute properly. If you want to delete columns from a bound DataGrid then you need to delete the field from the underlying Binding Source.

Hope this helps
 
Share this answer
 
v2
Thanx Wayne. But can u tell me how to delete from the underlying Binding Source????
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900