我想在其他特定单元格中输入鼠标时禁用 ButtonEdit 编辑器单元格。我怎样才能实现这个功能?
就像,只要我的鼠标悬停在 Ammar 单元格上,就必须像第1行和第3行一样禁用删除按钮。
注意: 选择列为RepositoryItemButtonEdit
列。
这是我的MouseMove
事件:
Private Sub gridViewLevel1_MouseMove(sender As Object, e As MouseEventArgs)
' Get a View at the current point.
Dim view As BaseView = GridControl.GetViewAt(e.Location)
' Retrieve information on the current View element.
Dim baseHI As BaseHitInfo = view.CalcHitInfo(e.Location)
Dim gridHI As GridHitInfo = TryCast(baseHI, GridHitInfo)
'Get Field Value
Dim fieldName As String = gridHI.View.GetRowCellValue(gridHI.RowHandle, gridHI.Column)
Dim row As DataRow = Nothing
If Not gridHI Is Nothing Then
lblHitInfo.Text = fieldName
row = gridHI.View.GetDataRow(gridHI.RowHandle)
Else
End If
End Sub
通过这种方式,我得到了DataRow
但接下来要做什么?
答案 0 :(得分:0)
我不是绝对清楚你尝试做什么,但我会尝试使用CustomRowCellEdit
事件来影响编辑器,具体取决于行数据。在这种情况下,您可以设置与您的逻辑相对应的e.RepositoryItem
,例如将它设置为buttonedit的一个只读实例或一个不可读的实例。
通常,您可以将行对象强制转换为实际的数据类型,如下所示:
var myData = gridView.GetRow(rowHandle) as MyData;
if(myData.Foo)
e.RepositoryItem = myReadonlyEditor;
else
e.RepositoryItem = myNormalEditor;
答案 1 :(得分:0)
答案 2 :(得分:0)
您可以使用GridView.CustomDrawCell
事件在单元格中绘制禁用状态。为此,每当单元符合您的条件时,您需要调用GridView.InvalidateRowCell
方法重绘特定单元格
这是一个例子:
Private disabledRowHandle? As Int32
Private disabledColumn As GridColumn
Private Sub GrdView_MouseMove(sender As Object, e As MouseEventArgs) Handles GrdView.MouseMove
' Get a View at the current point.
Dim view = TryCast(GrdCntrlMain.GetViewAt(e.Location), GridView)
' Retrieve information on the current View element.
Dim gridHI = view.CalcHitInfo(e.Location)
Dim redrawPrevious = True
Dim drawDisabled = False
If gridHI.InColumn Or gridHI.InDataRow Then
Dim cellValue As String = gridHI.View.GetRowCellValue(gridHI.RowHandle, gridHI.Column)
If cellValue = "Ammar" Then
If Not disabledRowHandle.Equals(gridHI.RowHandle) Then
drawDisabled = True
Else
redrawPrevious = False
End If
End If
End If
If redrawPrevious AndAlso disabledRowHandle.HasValue Then
Dim rowHandle = disabledRowHandle.Value
disabledRowHandle = Nothing
view.InvalidateRowCell(rowHandle, disabledColumn)
End If
If drawDisabled Then
If IsNothing(disabledColumn) Then
disabledColumn = GrdView.Columns("Select")
End If
disabledRowHandle = gridHI.RowHandle
view.InvalidateRowCell(disabledRowHandle.Value, disabledColumn)
End If
End Sub
Private Sub GrdView_CustomDrawCell(sender As Object, e As RowCellCustomDrawEventArgs) Handles GrdView.CustomDrawCell
If disabledRowHandle.Equals(e.RowHandle) AndAlso e.Column Is disabledColumn Then
Dim currentColor = e.Appearance.ForeColor
Dim currentUseForeColor = e.Appearance.Options.UseForeColor
e.Appearance.ForeColor = CommonSkins.GetSkin(UserLookAndFeel.Default).Colors.GetColor(CommonColors.DisabledText)
e.Appearance.Options.UseForeColor = True
e.DefaultDraw()
e.Appearance.ForeColor = currentColor
e.Appearance.Options.UseForeColor = currentUseForeColor
e.Handled = True
End If
End Sub