[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
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.
Re: [2005] Dictionary Obejct
The strings will be unique.Wht u do mean by create a second Dictionary ?
Re: [2005] Dictionary Obejct
Or Can I have any Anyother method ?
Re: [2005] Dictionary Obejct
Quote:
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.
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 :rolleyes:
Re: [2005] Dictionary Obejct
Quote:
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 :rolleyes:
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?
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")
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?