Record Position

  • Thread starter Thread starter Mark Vergara
  • Start date Start date
M

Mark Vergara

Hi to all,

I want to know if there is a way of getting the position of the
particular record in the dataset aside from CurrencyManger.position
let say for example we have a record..

cntID Name
1 Richard
2 Lucas
3 Jesus


I want to know the position of Jesus in the Record number 3 in the
dataset, if there is any please share it to me...


Thanks
Mark
 
you could loop thrue all the records to check if its the one you need
for doing w you want i would suggest using a dataview instaid of a dataset,
just create a new view w the table of the dataset and use the find function.

eric
 
Mark,

I've been trying to figure out the same thing, and have
posted here before, but have not come up with a good
answer yet, other than looping through all the rows to
find a match.

I've played with hooking the ListChanged event on the
dataview, which returns the old and the new index of a
changed/added item in the list, but haven't found any
consistency in the results. Because the index of any/all
rows changes when you do an insert, you can get a lot of
events raised when you do a single insert. For example,
when you add an item to an unsorted list, you get a
single event with event-type "add" and the index where
you'd expect it (at the end). But, if you add to a
sorted list, in the cases I tried it added my new record
at the beginning (index 0), and then fired off more
events as it "moved" it into the right sorted position in
the list. As this move was happening, I'm not sure why I
didn't get even more events, as the indices of the other
items in the list had to have been changing around as
well. Finally, if the change you make to the list
entails wholesale changes to the indices in the list,
you'll get a single event type ("reset", I think) that
basically says the changes were so drastic that you
shouldn't bother looking at each event.

You'd think there'd be something like a "record id" which
doesn't change as you move things around, but I haven't
found it yet.

Also, if you don't mind sorting the dataview, you can use
myDataview.Find to find the index of your key. That's
probably more efficient than looping through the
collection of rows yourself, but I don't know. I'd sure
think there's a raw iteration of an unordered list
somewhere, rather than doing your own foreach, but I
haven't found it.

HTH,

Bill Borg
 
Hi Mark,

Reading the answer, I don't believe that you can find with a dataview, a
seek, a sort, a select a position of a datarow in a dataset. You can find a
datarow or an array of datarows with that.

I give you an example roughly written here.
\\\
dim position as integer
for position = 0 to dataset.tables(0).rows.count-1
if dataset.tables(0).rows(position).item("name") = "Jezus"
'you have you position, if it is the first it is very fast
exit for
end if
next
///
I think that all other methods (if they could work) will cost more time
because the need internaly to do something the same especially a sort from a
big dataset.

I hope this helps a bit?

Cor
 
Back
Top