DataTable and DataView

  • Thread starter Thread starter Ruslan
  • Start date Start date
R

Ruslan

Hello,



I have:



BindingManagerBase bm;

DataTable myTable;

DataView myDataView

DataGrid myGrid;



myDataView = myTable["tab"] // data in table exist



myDataView.Sort = "field1";

myGrid.DataSource = myDataView;

bm = this.BindingContext[myDataView];



the data order in DataView and DataTable is different.



How can a read (change) the data in table using DataView?



Any idea?



Thanks a lot,

Ruslan
 
Hi,

The myDataView.Sort = "field1" causes the DataView to present the data
sorted by 'field1' presumably the data in the DataTable is either unsorted
or it is sorted on a different field.

Hope this helps

Chris Taylor
 
Chris and Ruslan,

Additionally, you can change the data by modifying the DataRowView that
is returned from the indexer on the DataView. The view is nothing more than
a way of viewing the underlying data, and you should be able to set the
values on the view like you would a table (as the view points to the
underlying table/row ultimately).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Chris Taylor said:
Hi,

The myDataView.Sort = "field1" causes the DataView to present the data
sorted by 'field1' presumably the data in the DataTable is either unsorted
or it is sorted on a different field.

Hope this helps

Chris Taylor
Ruslan said:
Hello,



I have:



BindingManagerBase bm;

DataTable myTable;

DataView myDataView

DataGrid myGrid;



myDataView = myTable["tab"] // data in table exist



myDataView.Sort = "field1";

myGrid.DataSource = myDataView;

bm = this.BindingContext[myDataView];



the data order in DataView and DataTable is different.



How can a read (change) the data in table using DataView?



Any idea?



Thanks a lot,

Ruslan
 
Hi Ruslan,
I think that you would have to bind the dataview to a control which makes it
you possible to change and enter the data.

Otherwise your dataview is almost without sence.

If you don't do that, you do'nt need the dataview but can direct change the
dataset by changing the values with something like

dataset.table(0).rows()(item) = "Ruslan" 'asuming it is a string

I hope this helps a little bit.

Cor
 
Back
Top