DataTable and DataView

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
 
C

Chris Taylor

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
 
N

Nicholas Paldino [.NET/C# MVP]

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
 
C

Cor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top