About arraylist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhii
    New Member
    • Feb 2008
    • 30

    About arraylist

    Hi Everyone,
    plz help me out folks...m trying to solve this problem from last 3 days but it is still not getting solved....Probl em is I am passing one arraylist from one form to other form...and in constructor of that second form i am copying that array in the two new different arraylist by saying new arraylist..
    and in further functions i am changing the content of one arraylist but problem is that this changes are getting reflected in other array too....& i dont want this to b done...plz help me out.....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by abhii
    Hi Everyone,
    plz help me out folks...m trying to solve this problem from last 3 days but it is still not getting solved....Probl em is I am passing one arraylist from one form to other form...and in constructor of that second form i am copying that array in the two new different arraylist by saying new arraylist..
    and in further functions i am changing the content of one arraylist but problem is that this changes are getting reflected in other array too....& i dont want this to b done...plz help me out.....
    Post the code you used and point out which "other" ArrayList is being incorrectly changed.

    Comment

    • abhii
      New Member
      • Feb 2008
      • 30

      #3
      Originally posted by r035198x
      Post the code you used and point out which "other" ArrayList is being incorrectly changed.
      THE BOLD CONTENT IS THE ARRAY WHICH I AM PASSING......

      private void renameVariableT oolStripMenuIte m_Click(object sender, EventArgs e)
      {

      //MessageBox.Show ("" + m_CaseData.Case Vars.Count);
      //from here cal to the form with required params....
      oFormVariabelPr operties = new frmVarPropertie s(m_CaseData.Case Vars,(int)m_GridCon trol.CurrentCel l.Col-1);

      if (oFormVariabelP roperties.ShowD ialog() == DialogResult.OK )
      {
      if (oFormVariabelP roperties.flag == true)
      {
      //m_CaseData.Rena meVariable(m_Gr idControl.Curre ntCell.Col-1,)

      }
      //set value to engine
      else if (oFormVariabelP roperties.flag == false)
      oFormVariabelPr operties.ShowDi alog();

      }

      }



      SECOND FORM IS: HERE TEMPCASEVARS IS AN ARRAY IN WHICH M DOING THE CHANGE N THIS CHANGES R GETTING REFLECTED IN THE TCASEVARS...

      using System;
      using System.Collecti ons.Generic;
      using System.Componen tModel;
      using System.Data;
      using System.Drawing;
      using System.Text;
      using System.Windows. Forms;
      using CaseDataLib;
      using System.Collecti ons;

      namespace CaseEditor
      {
      public partial class frmVarPropertie s : Form
      {
      const int Zero=0;
      CaseVariable objCaseVariable ;
      public Boolean flag = false;
      public Boolean Nextflag = false;
      public Boolean Prevflag = false;
      public Boolean leaveflag = false;
      int index;
      private ArrayList TempCaseVars;
      private ArrayList TCaseVars;
      //private String[] Description;

      public frmVarPropertie s(ArrayList CaseVars, int lColIndex)
      {

      long j = 0;
      //CaseVariable obj;
      InitializeCompo nent();
      TempCaseVars = new ArrayList(CaseV ars);
      TCaseVars = new ArrayList();
      TCaseVars = CaseVars;
      //TCaseVars = (ArrayList)Case Vars.Clone();
      //TCaseVars = CaseVars;
      //Description = new string[TempCaseVars.Co unt];
      //TempCaseVars = CaseVars;
      objCaseVariable = (CaseVariable)T empCaseVars[(int)lColIndex];
      txtBoxVariableD etailName.Text = objCaseVariable .VariableName;
      txtBoxVariableD etailDescriptio n.Text = objCaseVariable .Description;
      cbBoxVariableDe tailType.Text = cbBoxVariableDe tailType.Items[(int)objCaseVar iable.VariableT ype].ToString();

      // this is for addind all the existing var in the list
      for (int i = 0; i < TempCaseVars.Co unt; i++)
      {
      objCaseVariable = (CaseVariable)T empCaseVars[i];
      lstVariableList .Items.Add(objC aseVariable.Var iableName);
      }

      //this is for highlighting the renamed variable
      for (int i = 0; i < TempCaseVars.Co unt; i++)
      {
      if (lstVariableLis t.Items[i].ToString() == txtBoxVariableD etailName.Text)
      {
      lstVariableList .SetSelected(i, true);

      }
      }

      if (lColIndex+1==l stVariableList. Items.Count)
      {
      btnVariableDeta ilNext.Enabled = false;
      }

      if (lColIndex == Zero)
      {
      btnVariableDeta ilPrevious.Enab led = false;
      }

      if(lstVariableL ist.Items.Count ==1)
      {
      btnVariableDeta ilNext.Enabled = false;
      btnVariableDeta ilPrevious.Enab led = false;
      }

      }

      private void comboBox1_Selec tedIndexChanged (object sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = true;
      }

      private void comboBox2_Selec tedIndexChanged (object sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = true;
      }

      private void Prev_Next_Click ()
      {
      btnVariableDeta ilRestore.Enabl ed = true;

      objCaseVariable = (CaseVariable)T empCaseVars[lstVariableList .SelectedIndex];



      if (txtBoxVariable DetailName.Text != lstVariableList .SelectedItem.T oString())
      objCaseVariable .VariableName = txtBoxVariableD etailName.Text;

      if (txtBoxVariable DetailName.Text != lstVariableList .SelectedItem.T oString())
      {
      if (txtBoxVariable DetailDescripti on.Text != objCaseVariable .Description)
      objCaseVariable .Description = txtBoxVariableD etailDescriptio n.Text;
      index = lstVariableList .SelectedIndex;
      lstVariableList .Items.RemoveAt (index);
      lstVariableList .Items.Insert(i ndex, txtBoxVariableD etailName.Text) ;
      lstVariableList .SelectedIndex = index;


      }
      else
      if (txtBoxVariable DetailName.Text == lstVariableList .SelectedItem.T oString())
      {
      if (txtBoxVariable DetailDescripti on.Text != objCaseVariable .Description)
      {
      MessageBox.Show ("Duplicate Variable");
      if (Nextflag == true)
      lstVariableList .SetSelected(ls tVariableList.S electedIndex + 1, true);
      else
      lstVariableList .SetSelected(ls tVariableList.S electedIndex - 1, true);
      Nextflag = false;
      Prevflag = false;
      if (lstVariableLis t.SelectedIndex == Zero)
      btnVariableDeta ilPrevious.Enab led = false;
      //Temp[lstVariableList .SelectedIndex] = objCaseVariable .Description;

      //break;
      }
      }


      if (Nextflag == true)
      {
      if (lstVariableLis t.SelectedIndex == Zero)
      btnVariableDeta ilPrevious.Enab led = false;
      else
      btnVariableDeta ilNext.Enabled = true;

      for (; lstVariableList .SelectedIndex < lstVariableList .Items.Count; )
      {
      lstVariableList .SelectedIndex = lstVariableList .SelectedIndex + 1;

      if (lstVariableLis t.SelectedIndex + 1 == lstVariableList .Items.Count)
      {
      btnVariableDeta ilNext.Enabled = false;
      }
      lstVariableList .SetSelected(ls tVariableList.S electedIndex, true);

      txtBoxVariableD etailName.Text = lstVariableList .Items[lstVariableList .SelectedIndex].ToString();
      objCaseVariable = (CaseVariable)T empCaseVars[lstVariableList .SelectedIndex];

      break;
      }
      Nextflag = false;

      }

      else
      if (Prevflag == true)
      {
      if (lstVariableLis t.SelectedIndex != lstVariableList .Items.Count - 1)
      {
      btnVariableDeta ilNext.Enabled = true;
      }

      for (; lstVariableList .SelectedIndex >= Zero; ) //only till the first item
      {

      lstVariableList .SetSelected(ls tVariableList.S electedIndex - 1, true);
      txtBoxVariableD etailName.Text = lstVariableList .SelectedItem.T oString();
      objCaseVariable = (CaseVariable)T empCaseVars[lstVariableList .SelectedIndex];
      cbBoxVariableDe tailType.Text = cbBoxVariableDe tailType.Items[(int)objCaseVar iable.VariableT ype].ToString();
      txtBoxVariableD etailDescriptio n.Text = objCaseVariable .Description;

      if (lstVariableLis t.SelectedIndex <= Zero)
      {
      btnVariableDeta ilPrevious.Enab led = false;
      }
      break;
      }
      Prevflag = false;
      }
      }

      private void btnVariableDeta ilNext_Click(ob ject sender, EventArgs e)
      {
      Nextflag = true;
      Prev_Next_Click ();
      }

      private void btnVariableDeta ilPrevious_Clic k(object sender, EventArgs e)
      {
      Prevflag = true;
      Prev_Next_Click ();
      }

      private void lstVariableList _SelectedIndexC hanged(object sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = true;

      if (lstVariableLis t.Items.Count != 1) //should not go inside when there is only 1 item
      {
      if (lstVariableLis t.SelectedIndex == lstVariableList .Items.Count - 1)
      {
      btnVariableDeta ilNext.Enabled = false;
      btnVariableDeta ilPrevious.Enab led = true;
      }

      if (lstVariableLis t.SelectedIndex == Zero)
      {
      btnVariableDeta ilPrevious.Enab led = false;
      btnVariableDeta ilNext.Enabled = true;
      }
      if (lstVariableLis t.SelectedIndex >= 1)
      btnVariableDeta ilPrevious.Enab led = true;

      if (lstVariableLis t.SelectedIndex < lstVariableList .Items.Count - 1)
      btnVariableDeta ilNext.Enabled = true;



      }

      if (lstVariableLis t.SelectedIndex >= Zero)
      // because when the contol comes after changing the textbox data selected index is becoming as -1
      {
      objCaseVariable = (CaseVariable)T empCaseVars[lstVariableList .SelectedIndex];
      txtBoxVariableD etailName.Text = lstVariableList .Items[lstVariableList .SelectedIndex].ToString();
      cbBoxVariableDe tailType.Text = cbBoxVariableDe tailType.Items[(int)objCaseVar iable.VariableT ype].ToString();
      txtBoxVariableD etailDescriptio n.Text = objCaseVariable .Description;
      }
      }

      private void btnVariableDeta ilRestore_Click (object sender, EventArgs e)
      {
      lstVariableList .Items.Clear();
      for (int i = 0; i < TempCaseVars.Co unt; i++)
      {
      objCaseVariable = (CaseVariable)T CaseVars[i];
      lstVariableList .Items.Add(objC aseVariable.Var iableName);
      }
      lstVariableList .SetSelected(Ze ro, true);
      txtBoxVariableD etailName.Text = lstVariableList .Items[0].ToString();


      }

      private void frmVarPropertie s_Load(object sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = false;
      }

      private void txtBoxVariableD etailName_TextC hanged(object sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = true;
      }

      private void txtBoxVariableD etailDescriptio n_TextChanged(o bject sender, EventArgs e)
      {
      btnVariableDeta ilRestore.Enabl ed = true;

      }

      private void btnVariableDeta ilOK_Click(obje ct sender, EventArgs e)
      {
      if (txtBoxVariable DetailName.Text =="")
      {
      MessageBox.Show ("Enter Value");
      txtBoxVariableD etailName.Focus ();
      flag = false;
      return;
      }
      else
      flag = true;
      }






      }
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Try using
        TCaseVars = new ArrayList(CaseV ars);
        instead of
        TCaseVars = CaseVars;

        Comment

        • abhii
          New Member
          • Feb 2008
          • 30

          #5
          Originally posted by r035198x
          Try using
          TCaseVars = new ArrayList(CaseV ars);
          instead of
          TCaseVars = CaseVars;
          i tried sir but still its not working

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by abhii
            i tried sir but still its not working
            Clone it then
            TCaseVars = CaseVars.Clone( );
            Do the same for TempCaseVars

            Comment

            • abhii
              New Member
              • Feb 2008
              • 30

              #7
              Originally posted by r035198x
              Clone it then
              TCaseVars = CaseVars.Clone( );
              Do the same for TempCaseVars
              ]No SIR, Still it is changing the content

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by abhii
                ]No SIR, Still it is changing the content
                How did you determine that changes you made in one ArrayList are also occuring to another ArrayList?

                Comment

                • abhii
                  New Member
                  • Feb 2008
                  • 30

                  #9
                  Originally posted by r035198x
                  How did you determine that changes you made in one ArrayList are also occuring to another ArrayList?
                  by debugging only....when i changes the content of TempCaseVars as vaiable name var1 to "aaa" this change at that piont only getting reflected into that TCaseVars also....i have seen it by debugging only...

                  Comment

                  • abhii
                    New Member
                    • Feb 2008
                    • 30

                    #10
                    Originally posted by abhii
                    by debugging only....when i changes the content of TempCaseVars as vaiable name var1 to "aaa" this change at that piont only getting reflected into that TCaseVars also....i have seen it by debugging only...
                    hello sir...i m waiting for the reply

                    Comment

                    • abhii
                      New Member
                      • Feb 2008
                      • 30

                      #11
                      HELLO sir i did it....but thanx for replying me.....

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by abhii
                        HELLO sir i did it....but thanx for replying me.....
                        What did you do then?

                        Comment

                        Working...