DataView and DataViewRows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataView and would like to extract data from it and write it to a
ListView.

Can I only accomplish this with the DataViewRows Object array? Is there a
way forme to enumerate through the rows of the DataView without using the
DataViewRows array?

TIA,
 
Joe,

You make me curious why, what can be shorter than something like this.

\\
DataView dv = new DataView(dt);
dv.Sort = "bla"; // sorts column bla
DataTable dtnew = dt.Clone();
foreach (DataRowView dvr in dv)
dtnew.ImportRow(dvr.Row);
dt.Clear();
dt = dtnew.Copy();
///
This sample that I made creates a sorted datatable, however should be usable
with a listview as well.

Cor
 
Hi,

What is wrong with the DataViewRows ?

in fact you dont even have to use it in a foreach , you can simnply do:
foreach( DataViewRow row in dataview_variable)

Cheers,
 
Cor,

You answered my question. I have an app that creates a DataView from a
DataTable. Then I created a DataViewRows array and walked through the array
to retrieve its data. Clumsy, but it works.

Then I realized that this was inefficient, so I learned how to created a
DataView which only contained the data that I wanted. My question was how do
I enumerate through this DataView without creating another DataViewRows
array. The answer is below:

foreach (DataViewRow dvr in dv)
blah, blah, blah

Thanks!
 
Please see response above.

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

What is wrong with the DataViewRows ?

in fact you dont even have to use it in a foreach , you can simnply do:
foreach( DataViewRow row in dataview_variable)

Cheers,
 
Joe:

One thing that important to realize is that the DataView does not, itself,
contain any data. A view is nothing more than a set of pointers
(references) to rows in the underlying DataTable. When you iterative over
this structure, you are acually following an ordered set of references and
pulling the data from the underlying DataTable structure.

John
 
Thanks John. I appreciate the information.

John Puopolo said:
Joe:

One thing that important to realize is that the DataView does not, itself,
contain any data. A view is nothing more than a set of pointers
(references) to rows in the underlying DataTable. When you iterative over
this structure, you are acually following an ordered set of references and
pulling the data from the underlying DataTable structure.

John
 
Back
Top