Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the position of a record? 1

Status
Not open for further replies.

bmarks

IS-IT--Management
Sep 25, 2001
85
CA
I want to find out the position number of a particular record (Me.BindingContext(objCorpHO, "Corp_ho").Position).

I have a form that I created with the "Data From Wizard". It is based on one table and shows some of the fields in that table (like ClientID, ClientName, etc). The form shows the first record with previous/next record buttons that have the code Me.BindingContext(objCorpHO, "Corp_ho").Position = (Me.BindingContext(objCorpHO, "Corp_ho").Position + 1).

What I want to do is to have the user input the ClientID of one of the clients (would not be the one currently displayed) and the code needs to find the position number of that record.

Can someone tell me how to do this, or point me in the right direction?

Thanks.
 
Just out of curiocity, what are you going to do with the position number once you have it? There may be an easier way to get where you are going.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I want to use it with:

Me.BindingContext(objCorpHO, "Corp_ho").Position = ??? where ??? is the position found

to move the user to the record that matches their search.


I had posted in two different forums looking for a solution on how to get the user to that record, but had no replies at all. I then came up with this method as a possibility, but wasn't sure how to execute on it fully.
 
I'm not a big fan of binding GUI controls to Data directly, so someone else may have a better idea on this.

That being said, you could set the search function up to loop through all of the records in your data table, and track a counter/position indicator while looping. Then pass that value to the position tag.

Another option would be to use the .Select method to return an array of DataRows, then display that data in your GUI.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Hi Rick,

Thanks. I know this is probably not the best way to go about it, but I'm new to VB and I'm just trying to make it work at this point and will refine in when my knowledge level increases.

The search is what I am trying to do. Just was not sure how to properly do the looping through the records. I think I might have it now - but I think it's probably using the long way around.

I did not want to return an array, as I wanted to keep all the data and just display the record they want. I was thinking this as the user will want to modify multiple records.
 
I would say, try something like this:
Code:
dim iCounter as integer
dim bRecordFound as boolean = false

for iCounter = 0 to dtMyTable.rows.count-1
  if dtMyTable.rows(iCounter).item("FieldName") = SearchValue Then
    bRecordFound = True
    Exit For
  end if
next

if bRecordFound then
  Me.BindingContext(objCorpHO, "Corp_ho").Position = iCounter
else
  messagebox.show ("Search string not found")
end if

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I still remember the first class I had that dealt with the currency manager. I spent half the class wonder what the hell this has to do with money.

I found it about as useful as lead swim trunks. But then again, I'm not a fan of bound data, so take my opinion with a grain of salt. ;)

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Thanks for your responses. I now have this working. I am using something similar to the code that Rick provided. It's not the best solution, but one that works and that's what matters right now.

I will look at the currency manager example provided by RiverGuy. I think it should help for other items as well.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top