Home All Groups Group Topic Archive Search About

Converting between RowViews & Rows

Author
25 Apr 2006 2:45 PM
Ant
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());
}

Author
26 Apr 2006 9:19 PM
Mark Ashton
Try
foreach(DataRowView drv in dr)
{
    dsMaster.CustomersRow cr = drv.Row as dsMaster.CustomersRow;
    if (null != cr)
    {
        MessageBox.Show(cr.City.ToString());
    }
}

Show quote
"Ant" wrote:

> 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());
> }
Author
30 Apr 2006 12:38 PM
Ant
Hi Mark,
Thanks very much for demystifying that for me. It works fine.

Regards
Ant

Show quote
"Mark Ashton" wrote:

> Try
> foreach(DataRowView drv in dr)
> {
>     dsMaster.CustomersRow cr = drv.Row as dsMaster.CustomersRow;
>     if (null != cr)
>     {
>         MessageBox.Show(cr.City.ToString());
>     }
> }
>
> "Ant" wrote:
>
> > 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());
> > }

AddThis Social Bookmark Button