|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Converting between RowViews & Rowsused 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()); } 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()); > } 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()); > > } |
|||||||||||||||||||||||