Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2006

Tip: Looking for answers? Try searching our database.

how to go to specific row in hashtable based on value - not key?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rich - 17 May 2006 16:29 GMT
Hello,

I populate a hashtable with recordID's in a "For i=0 to n" loop.  Some
recordID's are duplicate but for different rows (recordID is not a key field
in this scenario).  I use the value of "i" in the For loop as the key in the
hashtable (which is actually the currencyManager counter).  

Originally, I was using the recordID as the key and "i" as the value.  So if
I user needed to go to recordID = 12345, I just retrieve the corresponding
value for that key and make currencyManager go to that value.  But since I
now have duplicate RecordID's I can't use that as the key.  So I switched it
around where the value of "i" is now the key and the RecordID is the value.

I experimented with the DictionaryEntry object to retrieve the key based on
a value, but I have to loop through the entire hashtable to locate the
desired DictionaryEntry.  Is there a way to go to the desired row in the
Hashtable without having to loop?

Thanks,
Rich
housebuyer@gmail.com - 18 May 2006 00:43 GMT
I'm not sure what you're trying to accomplish.  It sounds like you've
created a "hashtable" which behaves just like a standard table -- the
hash key is a sequential value, which could just as well be the index
of a simple table.

I don't know what you're trying to retrieve, or why, but assuming you'd
like to get all your RecordIDs, I'd suggest adding a sequential
collision resolver to each record ID, and make the combined field the
key to your hash table.  The first record you add with a given RecordID
has a hash key of "RecordID" + "000".  Each time you attempt to add a
new record, you check to see if RecordIDnnn exists; if it does, you
increment nnn and check again, until you get a slot.  Retrieval is
similarly simple; start with RecordID000, and keep looking until you
get a not found.

Of course, this won't work if you're going to be randomly deleting
records, but it's my best (and only) attempt at trying to understand
what you want to accomplish and suggesting a solution.  Good luck.
creator_bob - 18 May 2006 01:00 GMT
How about using an arraylist in your hash table.  Everytime you add an
item, if there is something there already, add it to your list.
Cor Ligthert [MVP] - 18 May 2006 06:04 GMT
Rich,

If you have a hashtable and you cannot use the dictionary than probably you
have taken the wrong control.

The meanig from the hashtable is finding things fast by its key.

There is a hybrid by the way, named the sortedlist

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemcollectionssortedlistclasstopic.asp


I hope this helps,

Cor

> Hello,
>
[quoted text clipped - 22 lines]
> Thanks,
> Rich

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.