if(lstVariableList.SelectedIndex> = Zero) //因为当更改文本框数据后更改所选索引时,索引变为-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]。至串(); } private void frmVarProperties_Load(object sender,EventArgs e) { btnVariableDetailRestore.Enabled = false; } private void txtBoxVariableDetailName_TextChanged(object sender,EventArgs e) { bnnVariableDetailRestore.Enabled = true; } private void txtBoxVariableDetailDescription_TextChanged(object sender,EventArgs e) { btnVariableDetailRestore.Enabled = true; } private void btnVariableDetailOK_Click(object发件人,EventArgs e) { if(txtBoxVariableDetailName.Text =="") { MessageBox.Show(" Enter Value"); txtBoxV ariableDetailName.Focus(); flag = false; return; } else flag = true; } } } 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; } }} 这篇关于关于arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 22:51