get DataTable of a DataGrid

hamid

Well-known member
Joined
Jul 13, 2004
Messages
113
i have a datagrid with following code
Code:
this.dataSet11.Clear();
this.oleDbDataAdapter1.Fill(this.dataSet11,"ClientsTable");
this.dataGrid1.DataSource=this.dataSet11.Tables["ClientsTable"].DefaultView;
DataTable dataTable = (DataTable)dataGrid1.DataSource;
but app return error when try this line:
Code:
DataTable dataTable = (DataTable)dataGrid1.DataSource;
why?
i want this code for autoresize DataGrid, so let me know if you have a correct code for autoresizing datagrid. ;)
 
there isnt DataSource properties for table object! but i remove default view and it done.
Code:
this.dataSet11.Clear();
this.oleDbDataAdapter1.Fill(this.dataSet11,"ClientsTable");
this.dataGrid1.DataSource=this.dataSet11.Tables["ClientsTable"];
DataTable dataTable = (DataTable)dataGrid1.DataSource;
thank you
 
If you wanted to bind to the DefaultView, then cast the DataSource back to a DataView instead of DataTable. You would do that if you wanted to bind to a filtered or sorted list of records - things the DataView lets you do.

-ner
 
thanks Nerseus,
so if i want use DataView in my datagrid then how can i get DataTable from it?
 
Change sort to specific column

how can i change sort to specific column in datagrid, in fact i want sort column that user change focus to it.
maybe you can help me about it here before i create new topic ;)
 
Back
Top