|
-
Oct 19th, 2007, 12:29 AM
#1
[RESOLVED] [2005] Dictionary Obejct
Hi all,
Code:
Private LstTemp As Dictionary(Of TextBox, String) 'To store the Textbox associated with and name
I have Dictionary object collection which contains the
values of textbox and a string.Now I want to search for a particular
string in the collection and get the respective textbox control
How can I.
I Found that there are method called ContainsValue and Contains Key which returns Boolean value.Is there any method avaliable to get the item index
Thanks in Advance
Dana
Please mark you thread resolved using the Thread Tools as shown
-
Oct 19th, 2007, 12:50 AM
#2
Re: [2005] Dictionary Obejct
The point of a Dictionary is to find a value by its key, not to find a key by its value. If your Strings are unique then you should create a second Dictionary. Otherwise, all you can do is loop through the KeyValuePair objects in the collection, test the Value and, if it matches, get the Key. That said, if the Strings aren't unique then there may be multiple keys that correspond.
-
Oct 19th, 2007, 12:56 AM
#3
Re: [2005] Dictionary Obejct
The strings will be unique.Wht u do mean by create a second Dictionary ?
Please mark you thread resolved using the Thread Tools as shown
-
Oct 19th, 2007, 01:05 AM
#4
Re: [2005] Dictionary Obejct
Or Can I have any Anyother method ?
Please mark you thread resolved using the Thread Tools as shown
-
Oct 19th, 2007, 01:15 AM
#5
Re: [2005] Dictionary Obejct
 Originally Posted by danasegarane
The strings will be unique.Wht u do mean by create a second Dictionary ?
I mean what I hope would be obvious: create a Dictionary where the Strings are the keys and the TextBoxes are the values.
-
Oct 19th, 2007, 01:18 AM
#6
Re: [2005] Dictionary Obejct
Even though I create new Dictionary object with string as the key , I think i may not able to get the value
Please mark you thread resolved using the Thread Tools as shown
-
Oct 19th, 2007, 01:21 AM
#7
Re: [2005] Dictionary Obejct
 Originally Posted by danasegarane
Even though I create new Dictionary object with string as the key , I think i may not able to get the value 
How is that possible? If you have a Dictionary with the strings as the keys and the TextBoxes as the values then if you supply a string it will give you the TextBox. Why would it not?
-
Oct 19th, 2007, 02:03 AM
#8
Re: [2005] Dictionary Obejct
Thanks Jhon.I did like this
Code:
Private LstTemp As Dictionary(Of String, TextBox) 'To store the Textbox associated with and name
'Add items
LstTemp = New Dictionary(Of String, TextBox)
'LstTemp = New Hashtable
LstTemp.Add("preactivity", f.txtPreActivity)
LstTemp.Add("parallel", f.txtParallelActivity)
LstTemp.Add("postactivity", f.txtPostActivity)
'Get the Item
Dim ctl as Textbox=LstTemp("postactivity")
Please mark you thread resolved using the Thread Tools as shown
-
Oct 19th, 2007, 07:47 AM
#9
Junior Member
Re: [RESOLVED] [2005] Dictionary Obejct
I suspect you may need to re-evaluate what you're trying to do here.
If you want to find the ID of the textbox with a particular string in it, then loop through the Controls collection searching for textboxes, and then test the contents of those boxes?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|