else if (e.KeyChar == 68 || e.KeyChar == 100)//如果按下的是d,将跳转到form2 {
Form2 fs = new Form2();
fs.Show();
form2窗体代码 private void Form2_Load_1(object sender, EventArgs e)
{
MHouse h = ((Button)sender).Tag as MHouse; // 运行完这句就报错 这句是获得button上的id 他代表一个户id
textBox1.Text =h.Houseid.ToString();
int id = Convert.ToInt32(textBox1.Text);未处理的“System.InvalidCastException”类型的异常出现在 VirtualHouse.exe 中。其他信息: 无法将类型为“VirtualHouse.Form2”的对象强制转换为类型“System.Windows.Forms.Button”。
谢谢各位大侠帮忙··谢谢
Form2 fs = new Form2();
fs.Show();
form2窗体代码 private void Form2_Load_1(object sender, EventArgs e)
{
MHouse h = ((Button)sender).Tag as MHouse; // 运行完这句就报错 这句是获得button上的id 他代表一个户id
textBox1.Text =h.Houseid.ToString();
int id = Convert.ToInt32(textBox1.Text);未处理的“System.InvalidCastException”类型的异常出现在 VirtualHouse.exe 中。其他信息: 无法将类型为“VirtualHouse.Form2”的对象强制转换为类型“System.Windows.Forms.Button”。
谢谢各位大侠帮忙··谢谢
解决方案 »
- WCF已部署到IIS,但远程不能访问...
- 关于Button按钮为什么无法回车激发Click事件
- 在.net 中 用javascript 处理前台页面
- 请高手帮忙 池连接问题
- C# 到处繁体EXCEL后,繁体系统显示乱码;参考前辈的论坛http://bbs.csdn.net/topics/380005042?page=1;还是不行
- 如何判断对指定网站的连接是否成功?
- 如何在C#中连接一台远端的Oracle 9i数据库?
- 如何用vs2003导出不带.cs文件的asp.net程序?谢谢!
- 请问如何使用错误处理
- 求救,谁有做水晶报表方面的材料,可以给我介绍一下吗
- GDI+输入文字的宽度如何获取
- 双击datagridview空白行后,弹出选择窗口
这不写清楚了么。把窗体转换button错误了。
非常不理解。
换成
MHouse h = ((Form)sender).Tag as MHouse; // 运行完这句就报错 这句是获得button上的id 他代表一个户id
MHouse h = ((Button)sender).Tag as MHouse 这句代码是为了或得他的id h.house_id
完全的看不懂,你解释清楚呀。
可以运行 但是到了下一句 会报错
MHouse h = ((Form)sender).Tag as MHouse;
// MHouse h = ((Button)sender).Tag as MHouse;
textBox1.Text =h.Houseid.ToString(); int id = Convert.ToInt32(textBox1.Text);
未处理的“System.NullReferenceException”类型的异常出现在 VirtualHouse.exe 中。其他信息: 未将对象引用设置到对象的实例。
sender 指向窗体对象 可以转换成一个业务对象?
加个if(h!=null)看看 肯定为空
if(h!=null)
{
textBox1.Text =h.Houseid.ToString();
int id = Convert.ToInt32(textBox1.Text);
//这两句肯定不执行
}
这句就直接报错了 高手,请问下该怎么解决?
fs.Show();
Form2.cs:
string strNum="";
public Form2(string str)
{
strNum=str;
}
然后Load里面根据strNum读取信息放到文本框中如果只有一个就不用读数据库直接赋值
....Text=strNum;