在BindingNavigator中禁用PositionItem

时间:2012-05-04 00:05:00

标签: vb.net winforms

我使用

禁用了PositionItem框
BindingNavigatorPositionItem.Enabled = False

但每次我点击下一行时,它都会再次启用。

我甚至试图通过添加

强制禁用它
 Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
    BindingNavigatorPositionItem.Enabled = False
 End Sub

如果启用了,我该如何控制?

2 个答案:

答案 0 :(得分:2)

参考:MSDN - disable binding navigator

BindingNavigator按钮的Click事件是默认封装行为,可以根据BindingNavigatorPosition设置其他按钮的Enable属性,因此您可以设置Me.BindingNavigator1.PositionItem.Available = FalseBindingNavigatorPositionItem.Visible = False

您可以将事件的功能覆盖为:

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BindingNavigatorAddNewItem.Click  
  BindingNavigator1.BeginInvoke(New MethodInvoker(AddressOf DisableItems))  
End Sub 

Private Sub DisableItems()  
  BindingNavigatorMoveFirstItem.Enabled = False 
  BindingNavigatorDeleteItem.Enabled = False 
  BindingNavigatorAddNewItem.Enabled = False 
  BindingNavigatorMoveLastItem.Enabled = False 
  BindingNavigatorMoveNextItem.Enabled = False 
  BindingNavigatorMovePreviousItem.Enabled = False 
  BindingNavigatorPositionItem.Enabled = False 
End Sub`   

答案 1 :(得分:0)

您可以将BindingNavigatorPositionItem.Enabled = False语句放在 BindingNavigatorPositionItem CotFocus事件处理程序中,如下所示:

Private Sub BindingNavigatorPositionItem_GotFocus(ByVal sender As Object,
                                                  ByVal e As System.EventArgs) Handles BindingNavigatorPositionItem.GotFocus
    BindingNavigatorPositionItem.Enabled = False
End Sub