Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Need help with retrieving objects from collection arraylist (http://www.go4expert.com/forums/help-retrieving-objects-collection-t758/)

markyjj 25Apr2006 16:20

Need help with retrieving objects from collection arraylist
 
Can anyone give me any advice on the following.

Am trying to create code that shows the correct set of details when the Id number is entered. When I access the collectioon arrayList (REGList), the same set of details are always displayed. I cant seem to display the details in the collection arraylist for the relevant Id number. I tried using a foreach loop but this still doesnt work. The click event handler code am using is show below.
Code: C#

private void btnSearch_Click(object sender, System.EventArgs e)
{     
        string Id = txtStudID.Text;
        if(txtStudID.Text == "")
            MessageBox.Show("Please enter the 5 digit Student ID number and try again");
foreach(object o in RegList)
        {
            int Item = 0;
            int count = 0;
            count++;
           
            if(o.GetType() == typeof(string))
            {
                if(o.ToString() == Id)
                {
                    Item = count;
                   
                   
            txtFirstnm.Text = RegList[Item + 1].ToString();
            txtLastnm.Text = RegList[Item + 2].ToString();
            txtAddress.Text = RegList[Item + 3].ToString();
            txtCity.Text = RegList[Item + 4].ToString();
            txtCourse.Text = RegList[Item + 5].ToString();
            txtEmail.Text = RegList[Item + 6].ToString();
            txtPhone.Text = RegList[Item + 7].ToString();
            txtComment.Text = RegList[Item + 8].ToString();

                   

                   
                }   
               
            }

            }
        }

Thanks for any help

shabbir 25Apr2006 20:57

Re: Need help with retrieving objects from collection arraylist
 
Inside the foreach loop you have declared a variable and for each loop that is declared and assigned the same value and so it shows the same data always.


All times are GMT +5.5. The time now is 03:24.