473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

About arraylist

30
Hi Everyone,
plz help me out folks...m trying to solve this problem from last 3 days but it is still not getting solved....Problem 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.....
Mar 25 '08 #1
11 1200
r035198x
13,262 8TB
Hi Everyone,
plz help me out folks...m trying to solve this problem from last 3 days but it is still not getting solved....Problem 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.
Mar 25 '08 #2
abhii
30
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 renameVariableToolStripMenuItem_Click(object sender, EventArgs e)
{

//MessageBox.Show("" + m_CaseData.CaseVars.Count);
//from here cal to the form with required params....
oFormVariabelProperties = new frmVarProperties(m_CaseData.CaseVars,(int)m_GridControl.CurrentCell.Col-1);

if (oFormVariabelProperties.ShowDialog() == DialogResult.OK)
{
if (oFormVariabelProperties.flag == true)
{
//m_CaseData.RenameVariable(m_GridControl.CurrentCel l.Col-1,)

}
//set value to engine
else if (oFormVariabelProperties.flag == false)
oFormVariabelProperties.ShowDialog();

}

}



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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CaseDataLib;
using System.Collections;

namespace CaseEditor
{
public partial class frmVarProperties : 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 frmVarProperties(ArrayList CaseVars, int lColIndex)
{

long j = 0;
//CaseVariable obj;
InitializeComponent();
TempCaseVars = new ArrayList(CaseVars);
TCaseVars = new ArrayList();
TCaseVars = CaseVars;
//TCaseVars = (ArrayList)CaseVars.Clone();
//TCaseVars = CaseVars;
//Description = new string[TempCaseVars.Count];
//TempCaseVars = CaseVars;
objCaseVariable = (CaseVariable)TempCaseVars[(int)lColIndex];
txtBoxVariableDetailName.Text = objCaseVariable.VariableName;
txtBoxVariableDetailDescription.Text = objCaseVariable.Description;
cbBoxVariableDetailType.Text = cbBoxVariableDetailType.Items[(int)objCaseVariable.VariableType].ToString();

// this is for addind all the existing var in the list
for (int i = 0; i < TempCaseVars.Count; i++)
{
objCaseVariable = (CaseVariable)TempCaseVars[i];
lstVariableList.Items.Add(objCaseVariable.Variable Name);
}

//this is for highlighting the renamed variable
for (int i = 0; i < TempCaseVars.Count; i++)
{
if (lstVariableList.Items[i].ToString() == txtBoxVariableDetailName.Text)
{
lstVariableList.SetSelected(i, true);

}
}

if (lColIndex+1==lstVariableList.Items.Count)
{
btnVariableDetailNext.Enabled = false;
}

if (lColIndex == Zero)
{
btnVariableDetailPrevious.Enabled = false;
}

if(lstVariableList.Items.Count==1)
{
btnVariableDetailNext.Enabled = false;
btnVariableDetailPrevious.Enabled = false;
}

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = true;
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = true;
}

private void Prev_Next_Click()
{
btnVariableDetailRestore.Enabled = true;

objCaseVariable = (CaseVariable)TempCaseVars[lstVariableList.SelectedIndex];



if (txtBoxVariableDetailName.Text != lstVariableList.SelectedItem.ToString())
objCaseVariable.VariableName = txtBoxVariableDetailName.Text;

if (txtBoxVariableDetailName.Text != lstVariableList.SelectedItem.ToString())
{
if (txtBoxVariableDetailDescription.Text != objCaseVariable.Description)
objCaseVariable.Description = txtBoxVariableDetailDescription.Text;
index = lstVariableList.SelectedIndex;
lstVariableList.Items.RemoveAt(index);
lstVariableList.Items.Insert(index, txtBoxVariableDetailName.Text);
lstVariableList.SelectedIndex = index;


}
else
if (txtBoxVariableDetailName.Text == lstVariableList.SelectedItem.ToString())
{
if (txtBoxVariableDetailDescription.Text != objCaseVariable.Description)
{
MessageBox.Show("Duplicate Variable");
if (Nextflag == true)
lstVariableList.SetSelected(lstVariableList.Select edIndex + 1, true);
else
lstVariableList.SetSelected(lstVariableList.Select edIndex - 1, true);
Nextflag = false;
Prevflag = false;
if (lstVariableList.SelectedIndex == Zero)
btnVariableDetailPrevious.Enabled = false;
//Temp[lstVariableList.SelectedIndex] = objCaseVariable.Description;

//break;
}
}


if (Nextflag == true)
{
if (lstVariableList.SelectedIndex == Zero)
btnVariableDetailPrevious.Enabled = false;
else
btnVariableDetailNext.Enabled = true;

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

if (lstVariableList.SelectedIndex + 1 == lstVariableList.Items.Count)
{
btnVariableDetailNext.Enabled = false;
}
lstVariableList.SetSelected(lstVariableList.Select edIndex, true);

txtBoxVariableDetailName.Text = lstVariableList.Items[lstVariableList.SelectedIndex].ToString();
objCaseVariable = (CaseVariable)TempCaseVars[lstVariableList.SelectedIndex];

break;
}
Nextflag = false;

}

else
if (Prevflag == true)
{
if (lstVariableList.SelectedIndex != lstVariableList.Items.Count - 1)
{
btnVariableDetailNext.Enabled = true;
}

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

lstVariableList.SetSelected(lstVariableList.Select edIndex - 1, true);
txtBoxVariableDetailName.Text = lstVariableList.SelectedItem.ToString();
objCaseVariable = (CaseVariable)TempCaseVars[lstVariableList.SelectedIndex];
cbBoxVariableDetailType.Text = cbBoxVariableDetailType.Items[(int)objCaseVariable.VariableType].ToString();
txtBoxVariableDetailDescription.Text = objCaseVariable.Description;

if (lstVariableList.SelectedIndex <= Zero)
{
btnVariableDetailPrevious.Enabled = false;
}
break;
}
Prevflag = false;
}
}

private void btnVariableDetailNext_Click(object sender, EventArgs e)
{
Nextflag = true;
Prev_Next_Click();
}

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

private void lstVariableList_SelectedIndexChanged(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = true;

if (lstVariableList.Items.Count != 1) //should not go inside when there is only 1 item
{
if (lstVariableList.SelectedIndex == lstVariableList.Items.Count - 1)
{
btnVariableDetailNext.Enabled = false;
btnVariableDetailPrevious.Enabled = true;
}

if (lstVariableList.SelectedIndex == Zero)
{
btnVariableDetailPrevious.Enabled = false;
btnVariableDetailNext.Enabled = true;
}
if (lstVariableList.SelectedIndex >= 1)
btnVariableDetailPrevious.Enabled = true;

if (lstVariableList.SelectedIndex < lstVariableList.Items.Count - 1)
btnVariableDetailNext.Enabled = true;



}

if (lstVariableList.SelectedIndex >= Zero)
// because when the contol comes after changing the textbox data selected index is becoming as -1
{
objCaseVariable = (CaseVariable)TempCaseVars[lstVariableList.SelectedIndex];
txtBoxVariableDetailName.Text = lstVariableList.Items[lstVariableList.SelectedIndex].ToString();
cbBoxVariableDetailType.Text = cbBoxVariableDetailType.Items[(int)objCaseVariable.VariableType].ToString();
txtBoxVariableDetailDescription.Text = objCaseVariable.Description;
}
}

private void btnVariableDetailRestore_Click(object sender, EventArgs e)
{
lstVariableList.Items.Clear();
for (int i = 0; i < TempCaseVars.Count; i++)
{
objCaseVariable = (CaseVariable)TCaseVars[i];
lstVariableList.Items.Add(objCaseVariable.Variable Name);
}
lstVariableList.SetSelected(Zero, true);
txtBoxVariableDetailName.Text = lstVariableList.Items[0].ToString();


}

private void frmVarProperties_Load(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = false;
}

private void txtBoxVariableDetailName_TextChanged(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = true;
}

private void txtBoxVariableDetailDescription_TextChanged(object sender, EventArgs e)
{
btnVariableDetailRestore.Enabled = true;

}

private void btnVariableDetailOK_Click(object sender, EventArgs e)
{
if (txtBoxVariableDetailName.Text =="")
{
MessageBox.Show("Enter Value");
txtBoxVariableDetailName.Focus();
flag = false;
return;
}
else
flag = true;
}






}
}
Mar 25 '08 #3
r035198x
13,262 8TB
Try using
TCaseVars = new ArrayList(CaseVars);
instead of
TCaseVars = CaseVars;
Mar 25 '08 #4
abhii
30
Try using
TCaseVars = new ArrayList(CaseVars);
instead of
TCaseVars = CaseVars;
i tried sir but still its not working
Mar 25 '08 #5
r035198x
13,262 8TB
i tried sir but still its not working
Clone it then
TCaseVars = CaseVars.Clone();
Do the same for TempCaseVars
Mar 25 '08 #6
abhii
30
Clone it then
TCaseVars = CaseVars.Clone();
Do the same for TempCaseVars
]No SIR, Still it is changing the content
Mar 25 '08 #7
r035198x
13,262 8TB
]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?
Mar 25 '08 #8
abhii
30
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...
Mar 25 '08 #9
abhii
30
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
Mar 26 '08 #10
abhii
30
HELLO sir i did it....but thanx for replying me.....
Mar 26 '08 #11
r035198x
13,262 8TB
HELLO sir i did it....but thanx for replying me.....
What did you do then?
Mar 26 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: roy | last post by:
The following is a simple example I wrote. I want function makenull() to set the arraylist null. However, in this example, after coming back from makenull() function, s is still not null. I got...
4
by: bkazlak | last post by:
Hello, I have a quick question might help me understand garbage collection. let's say I'm having a static collection of objects in one class, so this collection should be cached and present...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
9
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am...
2
by: han zhiyang | last post by:
I saw the lecture video by Mr. Anders Hejlsberg on Tech-ed 2004 yesterday.There is a test on Generics performance,and I try it myself. But,the result is not the same as the videw shows.the...
3
by: Andy Chen | last post by:
Hi, I have a Hashtable, key is string and value is ArrayList. The problem is I cannot cast the value from object to ArrayList. like this: Hashtable ht = new Hashtable(); ArrayList al = new...
3
by: tony | last post by:
Hello! This method below works but how can it work when I don't have any open on myOleDbConnection ? As I have understood this is that there must exist an myOleDbConnection ..Open(); in my case...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
12
by: Gilbert | last post by:
H, i'm starting with asp.net/vb.net and have some questions about arrays and collections: 1) what's the difference between: dim x() as string and dim x as array
9
by: Adam Sandler | last post by:
Hello, I have 2 questions about using array lists. 1. I have a method which returns an arraylist. I'd like to put the contents of what is returned into another arraylist: ArrayList al =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.