Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Dictionary Obejct

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Dictionary Obejct

    Or Can I have any Anyother method ?
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  9. #9
    Junior Member
    Join Date
    Oct 2007
    Posts
    29

    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
  •  



Click Here to Expand Forum to Full Width