Need help with retrieving objects from collection arraylist

markyjj's Avatar, Join Date: Dec 2005
Go4Expert Member
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;
            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

Last edited by shabbir; 25Apr2006 at 20:55.. Reason: Proper formating
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.