datagridview 的 cellenter 和cellLeave 事件,当激发此单元格的行列相等时,如果改变此单元格的单元格类型时,为什么会引发InvalidoperationException异常?
解决方案 »
- 继续上次的 自定义容器写好了,现在要对容器里面的控件实现排序....如何实现
- 关于C#中多个窗体操作Excel的问题
- 求一正则匹配,大侠救命啊。
- 各位大侠 麻烦问一下 弹模态窗口 在IE6.0中可以 在IE7.0中 行不通,怎么解决啊 在线等待,谢谢
- 那位大侠有C#写的OPC客户端,小弟跪求了
- 请文MDI子窗体怎么写?
- 怎么用javascript获得服务器端的一个xml格式的字符串str
- 既然C#Web应用程序.aspx中不能使用拆分窗体,那么......??
- 谁有程序员大本营2001之C#的资料库
- 问一个简单的问题,就剩10分了,谁第一个答对就给谁
- sQL2000
- 帮忙哦:哪个说一下如何实现网吧系统.说一下思路哦.
用if判断下是否为null
{
if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() is DataGridViewComboBoxCell)
{
return;
}
dataGridView1[e.ColumnIndex, e.RowIndex] = new DataGridViewComboBoxCell();
}
改用_cellclick或者其他事件试试看
改用dataGridView1_CellClick事件是可以实现的 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() is DataGridViewComboBoxCell)
{
return;
}
dataGridView1[e.ColumnIndex, e.RowIndex] = new DataGridViewComboBoxCell();
}
不过用dataGridView1[e.ColumnIndex, e.RowIndex].GetType() is DataGridViewComboBoxCell判断是用问题的
“给定表达式始终不是所提供的(“系统 System .Windows .Forms .DataGridViewComboBoxCell ”类型)”
ByVal e As DataGridViewDataErrorEventArgs) _
Handles DataGridView2.DataError
Try ' If the data source raises an exception when a cell value is
' commited, display an error message.
If e.Exception IsNot Nothing AndAlso _
e.Context = DataGridViewDataErrorContexts.Commit Then MessageBox.Show("CustomerID value must be unique.") End If Catch ex As Exception End Try
End Sub
加這個試下