1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with retrieving objects from collection arraylist

Discussion in 'C#' started by markyjj, Apr 25, 2006.

  1. markyjj

    markyjj New Member

    Joined:
    Dec 7, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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:
    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
     
    Last edited by a moderator: Apr 25, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    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.
     

Share This Page