以下是winform的两个窗体来回传值.请看最后.最后是把得到的值删除掉.可是我想把这个值更新一下,也就是替换成别的值.请问应该调用什么方法?
谢谢.
以下是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.lstfirst.Items.Clear();
this.lstsecond.Items.Clear();
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "客户") == 0)
{
string[] names ={ "客户", "可忽忽", "可可忽忽" };
for (int i = 0; i < names.Length; i++)
{
this.lstfirst.Items.Add(names[i]);
}
}
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "人品") == 0)
{
string[] names ={ "很纯洁", "很一般", "很下流" };
for (int i = 0; i < names.Length; i++)
{
this.lstfirst.Items.Add(names[i]);
}
}
}
private void sendsigle_Click(object sender, EventArgs e)
{
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "客户") == 0)
{
string[] names ={ "客户", "可忽忽", "可可忽忽" };
System.Windows.Forms.ListBox.ObjectCollection obj = this.lstfirst.Items;
for (int i = 0; i < names.Length; i++)
{
if (string.Compare(this.lstfirst.SelectedItem.ToString(), names[i]) == 0)
{
this.lstsecond.Items.Add(names[i]);
for (int j = 0; j < obj.Count; j++)
{
if (obj[j].ToString().Equals(names[i]))
{
obj.RemoveAt(j);
}
}
}
}
}
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "人品") == 0)
{
string[] unames ={ "很纯洁", "很一般", "很下流" };
System.Windows.Forms.ListBox.ObjectCollection obj = this.lstfirst.Items;
for (int i = 0; i < unames.Length; i++)
{
if (string.Compare(this.lstfirst.SelectedItem.ToString(), unames[i]) == 0)
{
this.lstsecond.Items.Add(unames[i]);
for (int k = 0; k < obj.Count; k++)
{
if (obj[k].ToString().Equals(unames[i]))
{
obj.RemoveAt(k);
}
}
}
}
}
}
private void backsigle_Click(object sender, EventArgs e)
{
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "人品") == 0)
{
string[] unames ={ "很纯洁", "很一般", "很下流" };
System.Windows.Forms.ListBox.ObjectCollection obj = this.lstsecond.Items;
for (int i = 0; i < unames.Length; i++)
{
if (string.Compare(this.lstsecond.SelectedItem.ToString(), unames[i]) == 0)
{
this.lstfirst.Items.Add(unames[i]);
for (int k = 0; k < obj.Count; k++)
{
if (obj[k].ToString().Equals(unames[i]))
{
obj.RemoveAt(k);
}
}
}
}
}
}
private void sendall_Click(object sender, EventArgs e)
{
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "人品") == 0)
{
string[] unames ={ "很纯洁", "很一般", "很下流" };
for (int i = 0; i < unames.Length; i++)
{
this.lstsecond.Items.Add(unames[i]);
}
this.lstfirst.Items.Clear();
}
if (String.Compare(this.comboBox1.SelectedItem.ToString(), "客户") == 0)
{
string[] names ={ "客户", "可忽忽", "可可忽忽" };
for (int i = 0; i < names.Length; i++)
{
this.lstsecond.Items.Add(names[i]);
}
}
this.lstfirst.Items.Clear();
}
private void btnbackall_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("与上个全部移动相同。此略。");
}
private void btnreset_Click(object sender, EventArgs e)
{
string strName = this.lstsecond.SelectedItem.ToString();
System.Windows.Forms.ListBox.ObjectCollection obj = this.lstsecond.Items;
change cg = new change(strName,obj);
cg.MaximizeBox = false;
cg.MinimizeBox = false;
cg.Show();
}
}
}
=================================
第二个窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class change : Form
{
string name;
System.Windows.Forms.ListBox.ObjectCollection obj;
public change(string uname, System.Windows.Forms.ListBox.ObjectCollection oobj)
{
this.name = uname;
this.obj = oobj;
InitializeComponent();
}
private void change_Load(object sender, EventArgs e)
{
this.txtchange.Text = name;
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("是否删除", "确定",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (dr.Equals(DialogResult.Yes))
{
for (int i = 0; i < obj.Count; i++)
{
if (obj[i].ToString().Equals(name))
{
obj.RemoveAt(i);
break;
}
}
this.Close();
}
}
}
}
[此贴子已经被作者于2007-10-31 17:32:34编辑过]