| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 644 人关注过本帖
标题:再来请教一个问题.谢谢.(已经搞定.谢谢.)
只看楼主 加入收藏
uukkcc
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-7-24
收藏
 问题点数:0 回复次数:3 
再来请教一个问题.谢谢.(已经搞定.谢谢.)

以下是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编辑过]

搜索更多相关主题的帖子: using System public Drawing 
2007-10-29 20:35
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 
你知道怎么删除,不知道怎么修改?

Flying without wings
2007-10-29 22:20
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
原理一样

愛生活 && 愛編程
2007-10-29 22:53
baoguoping
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-10-29
收藏
得分:0 

加我QQ;一起研究吧......


为了梦一生;我的QQ:314479312;群:47407842对net有兴趣的朋友可以加入!!
2007-10-30 10:01
快速回复:再来请教一个问题.谢谢.(已经搞定.谢谢.)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029924 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved