I have a 'for each DataRow in DataTable.Rows loop and I need a way to jump
back to a privious row and continue the loop. I haven't been able to come up
with any clever ways of faking this since Bookmarks don't exist anymore:-(

Thnx,
Grayson

Re: How do I "Fake" a Bookmark? by Miha

Miha
Mon Dec 06 14:01:41 CST 2004

Hi Grayson,

You have several options:
- store primary key if there is one and then use DataRowCollection.Find
method
- do a for loop instead and store the index of row
- store a DataRow reference and do a foreach again (this should be the
slowest)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"Grayson" <grayson@community.nospam> wrote in message
news:3E175B69-6C52-4ADE-BE9E-D54FEED1A87C@microsoft.com...
>I have a 'for each DataRow in DataTable.Rows loop and I need a way to jump
> back to a privious row and continue the loop. I haven't been able to come
> up
> with any clever ways of faking this since Bookmarks don't exist anymore:-(
>
> Thnx,
> Grayson
>



Re: How do I "Fake" a Bookmark? by Sahil

Sahil
Mon Dec 06 14:23:23 CST 2004

Grayson,

To add bookmark functionality, you'd have to override the
IEnumerator.GetEnumerator function and basically implement your own
enumerator. When you'd do it, you'd realize why it was taken out - the
enumerator will now have to deal with remembering it's client's bookmarks -
not a good idea. So basically it's do-able, but it's a pain in the neck and
generally not recommended.

So I'd recommend "faking" it - by using a "For" loop instead of a foreach
loop, and storing the ordinal (index integer) of where you wanted your
bookmark to be, and thence start running the for loop from the bookmark
onwards.

In .NET 2.0, Enumerators are GREATLY simplified using a new keyword called
"yeild", and well - then it'd be much easier to implement bookmarks but you
still run into the problem mentioned in para #1. Essentially it will get
easier to implement though.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik





"Grayson" <grayson@community.nospam> wrote in message
news:3E175B69-6C52-4ADE-BE9E-D54FEED1A87C@microsoft.com...
> I have a 'for each DataRow in DataTable.Rows loop and I need a way to jump
> back to a privious row and continue the loop. I haven't been able to come
up
> with any clever ways of faking this since Bookmarks don't exist anymore:-(
>
> Thnx,
> Grayson
>



Re: How do I "Fake" a Bookmark? by grayson

grayson
Mon Dec 06 14:31:02 CST 2004

Hi Miha,

Thanx for the response.
The Find method returns a DataRowâ?¦. So

For Each dr in dt.Rows
If somethingâ?¦
Get the primary key
endif
if something else
dr = dt.Rows.find(primary key)
endif
Next

So if Iâ??m on row 3, get the key = 3
Then Iâ??m on row 10, set dr = 3, Iâ??ll get rows 3, 4, 5, ect again? Sounds too
easy:-)
Sorry Iâ??m not quit far enough along on this VB6 rewrite to be able to test
this just yet, but I will give it a try.


"Miha Markic [MVP C#]" wrote:

> Hi Grayson,
>
> You have several options:
> - store primary key if there is one and then use DataRowCollection.Find
> method
> - do a for loop instead and store the index of row
> - store a DataRow reference and do a foreach again (this should be the
> slowest)
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> SLODUG - Slovene Developer Users Group
> www.rthand.com
>
> "Grayson" <grayson@community.nospam> wrote in message
> news:3E175B69-6C52-4ADE-BE9E-D54FEED1A87C@microsoft.com...
> >I have a 'for each DataRow in DataTable.Rows loop and I need a way to jump
> > back to a privious row and continue the loop. I haven't been able to come
> > up
> > with any clever ways of faking this since Bookmarks don't exist anymore:-(
> >
> > Thnx,
> > Grayson
> >
>
>
>

Re: How do I "Fake" a Bookmark? by grayson

grayson
Mon Dec 06 14:51:03 CST 2004

Thanx Sahil!
Now I got the idea... Sometimes it takes awhile... , Sorry Miha. Use the
index number and I'm right back were I wanted to be and still moving forward.
Perfect

"Sahil Malik" wrote:

> Grayson,
>
> To add bookmark functionality, you'd have to override the
> IEnumerator.GetEnumerator function and basically implement your own
> enumerator. When you'd do it, you'd realize why it was taken out - the
> enumerator will now have to deal with remembering it's client's bookmarks -
> not a good idea. So basically it's do-able, but it's a pain in the neck and
> generally not recommended.
>
> So I'd recommend "faking" it - by using a "For" loop instead of a foreach
> loop, and storing the ordinal (index integer) of where you wanted your
> bookmark to be, and thence start running the for loop from the bookmark
> onwards.
>
> In .NET 2.0, Enumerators are GREATLY simplified using a new keyword called
> "yeild", and well - then it'd be much easier to implement bookmarks but you
> still run into the problem mentioned in para #1. Essentially it will get
> easier to implement though.
>
> - Sahil Malik
> http://dotnetjunkies.com/weblog/sahilmalik
>
>
>
>
>
> "Grayson" <grayson@community.nospam> wrote in message
> news:3E175B69-6C52-4ADE-BE9E-D54FEED1A87C@microsoft.com...
> > I have a 'for each DataRow in DataTable.Rows loop and I need a way to jump
> > back to a privious row and continue the loop. I haven't been able to come
> up
> > with any clever ways of faking this since Bookmarks don't exist anymore:-(
> >
> > Thnx,
> > Grayson
> >
>
>
>