补充一句,这两个用户控件是在windows窗体中!!!
解决方案 »
- TTS 中System.UnauthorizedAccessException: 拒绝访问。 (异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))
- 关于C#+Access做C/S架构
- 怎么用.NET控制计算机的关闭,重启,和开机呢(也就是说怎么用.NET控制计算机)?
- 抓取论坛数据
- 程序不能以其他帐号运行
- 我想用C#做一个禁止本地客户端发送邮件的程序该怎么做?
- 二进制文件
- if(null!=变量) 这种表达式是什么意思,为什么null放左边。
- 汉字转换拼音问题
- 向高手请教,正则表达式的解法!
- 请问两个问题
- 用c#处理文件夹中的某种文件 help!help!help
listview OnFocus()
{
comboBox .SelectedItem=?;
}
step 1:
在两个控件都认得的命名空间下定义一个委托和传的数据类;
//要传的数据类
public class heheEventArgs:EventArgs
{
//要传的string或者放个对象也可以!这里可以传你的listview的选中的值
public string xx;
}
//传输代理;
public delegate void heheHandler(object sender, heheEventArgs e);step 2:
在含listview的控件中添加一个
public event heheHandler heheevent;
在点击用户控件中listview的处理方法中添加:
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
heheEventArgs arg = new heheEventArgs();
arg.xx = "okle";//可以是你要传的数据
this.heheevent(this,arg);
}
step3:
在含comboBox的控件中添加一个处理方法:
public void heheforcomboBox(object sender, heheEventArgs e)
{
MessageBox.Show(e.xx);
this.comboBox1.Text = e.xx;//改变comboBox1的值。
}step 4:
在父窗体实例化含listview的控件时加如下代码:
this.实例化的含listview控件名.heheevent += new heheHandler(this.含comboBox控件名.heheforcomboBox); 原理:是子控件发一个Message给父控件,父控件收到Message后调用
另一子控件对应的方法。