Converting between RowViews & Rows

G

Guest

Hi, I'd like to use a typed row to iterate through a DatarowView array. I've
used a view for its FindRows method.

How (or where) can I cast this so that the rows & rowViews will work
together. I've tried converting them in various places without success:

Thanks for any ideas. I can use an untyped in the loop but I'm sure this
must be able to be done.

Ant

// Tried converting here with no success
DataView dv = new DataView(dsMaster.Customers);

dv.Sort = "City";

DataRowView[] dr = dv.FindRows("London");

// Doesn't like this. Tried converting here as well
foreach (dsMaster.CustomersRow cr in dr)
{

MessageBox.Show(cr.City.ToString());
}
 
G

Guest

Try
foreach(DataRowView drv in dr)
{
dsMaster.CustomersRow cr = drv.Row as dsMaster.CustomersRow;
if (null != cr)
{
MessageBox.Show(cr.City.ToString());
}
}
 
G

Guest

Hi Mark,
Thanks very much for demystifying that for me. It works fine.

Regards
Ant

Mark Ashton said:
Try
foreach(DataRowView drv in dr)
{
dsMaster.CustomersRow cr = drv.Row as dsMaster.CustomersRow;
if (null != cr)
{
MessageBox.Show(cr.City.ToString());
}
}

Ant said:
Hi, I'd like to use a typed row to iterate through a DatarowView array. I've
used a view for its FindRows method.

How (or where) can I cast this so that the rows & rowViews will work
together. I've tried converting them in various places without success:

Thanks for any ideas. I can use an untyped in the loop but I'm sure this
must be able to be done.

Ant

// Tried converting here with no success
DataView dv = new DataView(dsMaster.Customers);

dv.Sort = "City";

DataRowView[] dr = dv.FindRows("London");

// Doesn't like this. Tried converting here as well
foreach (dsMaster.CustomersRow cr in dr)
{

MessageBox.Show(cr.City.ToString());
}
 

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

Top