本示例展示了如何防止“ContactName”列被拖动到 “自定义”窗体。
为了控制网格列的拖动和放落,我们接管了
GridView.DragObjectOver 事件。 此事件的
DragObjectOverEventArgs.DropInfo 参数包含了关于当前位置的信息,在该位置上如果最终用户放落被拖动对象,则发生拖动和放落。
当拖动经过“自定义”窗体上面时
DragObjectOverEventArgs.DropInfo 的 Index 属性值为
-1。
C# | 复制代码 |
---|
using DevExpress.XtraGrid.Views.Base;
private void bandedGridView1_DragObjectOver(object sender, DragObjectOverEventArgs e) {
GridColumn column = e.DragObject as GridColumn;
if (column != null) {
e.DropInfo.Valid = !(e.DropInfo.Index == -1 && column.FieldName == "ContactName");
}
}
|
Visual Basic | 复制代码 |
---|
Imports DevExpress.XtraGrid.Views.Base
Private Sub BandedGridView1_DragObjectOver(ByVal sender As Object, _
ByVal e As DragObjectOverEventArgs) Handles BandedGridView1.DragObjectOver
If TypeOf e.DragObject Is GridColumn Then
Dim column As GridColumn = CType(e.DragObject, GridColumn)
e.DropInfo.Valid = Not (e.DropInfo.Index = -1 And column.FieldName = "ContactName")
End If
End Sub
|