accessing values from hash table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gurmeet07
    New Member
    • Mar 2008
    • 6

    #1

    accessing values from hash table

    hey guys i m new to .net and facing one problem

    on click of a button (saving the data to the hash table)
    like this :

    there are 7 textboxes and first textbox1.text is the key for hash table n all other textbox.text are values which are stored in an object type array.......... .

    object[] obj = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text };

    ht.Add(textBox1 .Text,obj);

    after save ---- all textboxes.text is set to blank so that user can either enter next values or can find out information of another paricular record......... .(function like find or search a record)

    now on click of another button i want to access values from hash table.......... ....
    which are to be displayed in the 7 textboxes ............ on the same form
    (this is the function of searching a record and displaying its content)

    i was using like : if(ht.ContainsK ey(textbox7.tex t))
    {
    ////////////// blah blah blah
    }

    please solve this blah blah blah........... .............
  • int08h
    New Member
    • Apr 2007
    • 28

    #2
    if (ht.ContainsKey (textBox7.Text) )
    {
    object[] array = (object[])ht[textBox7.Text];
    textBox1.Text = (string)array[0];
    //And so on
    }

    Comment

    • gurmeet07
      New Member
      • Mar 2008
      • 6

      #3
      hey thnx for that

      now is there any way by which i can loop on textboxes n in just two lines my work culd be possible instead of assigning values one by one to each textbox........ ..........i hope u got it wat i m asking???

      I mean smthing like

      int j=0;

      for(int i = 1; i <= (number of textboxes) ; i++)
      {
      textbox[i].text=array[j++];
      }

      Comment

      Working...