自定义DataGridView事件触发问题
怎么触发自定义的DataGridView的单元格双击事件啊?我是这样定义的:this.dataGridView1.Controls.Add(my_grid);
把这个DataGridView嵌入到界面上DataGridView的一个单元格里面的。在界面上这个DataGridView我可以点它属性触发它的事件,但我自定义的DataGridView要怎么去触发呢? 高手速度指点下啊,提供下代码参考。。 --------------------编程问答-------------------- 晕。怎么没人来指点下啊。。 急啊 --------------------编程问答-------------------- 我看了03的,老土,还没安05。03的是datagrid,自定义方法绑定的到双击事件中。你看看委托和事件可能就懂了 --------------------编程问答-------------------- 自定义事件意义不大,你想完成什么样的操作非要这么做吗 --------------------编程问答-------------------- 我也是,將KeyPreview設為True後,按Del,DataGridview沒有反應,只好重寫DataGridView:
Public Class CustomKeyEventDataGridView
Inherits DataGridView
Public Event RowRemoving(ByVal iRowIndex As Integer)
<System.Security.Permissions.UIPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, _
Window:=System.Security.Permissions.UIPermissionWindow.AllWindows)> _
Protected Overrides Function ProcessDialogKey( _
ByVal keyData As Keys) As Boolean
' Extract the key code from the key value.
Dim key As Keys = keyData And Keys.KeyCode
If key = Keys.Delete AndAlso Me.SelectedRows.Count > 0 Then
RaiseEvent RowRemoving(Me.CurrentRow.Index)
Return False ' Me.ProcessDeleteKey(keyData)
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, Flags:= _
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Protected Overrides Function ProcessDataGridViewKey( _
ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
If e.KeyCode = Keys.Delete AndAlso Me.SelectedRows.Count > 0 Then
Return Me.ProcessDeleteKey(e.KeyData)
End If
Return MyBase.ProcessDataGridViewKey(e)
End Function
End Class
自定義了RowRemoving事件,但在Winform中:
Private Sub RemoveRowing(ByVal iRow As Integer) Handles dgvDatas.rowremoving
End Sub
提示dgvDatas.rowremoving找不到事件.
怎麼辦? --------------------编程问答-------------------- 搞定了,原來在.Designer.vb文件中,dgvDatas為DataGridView,將它改為CustomKeyEventDataGridView 就可以了
补充:.NET技术 , C#