chlade
asked on
BindingNavigator disable problem
I am using a BindingNavigator to allow navigation through data on my form.
Depending on the situation, I either want to enable or disable the Delete button on the navigation bar (the red "X").
However, I am having problems getting this to work. Â I have narrowed it down to a situation where it appears certain things reset the enabled property.
For instance, if I have the form open and the delete button is disabled, if I do an AcceptChanges on the dataset, the BindingNavigator delete button resets to be enabled. Â If I add a line immediately after the ds.AcceptChanges to reset the button to be disabled, it works fine.
My question is why does this happen? Â What would be the best way to handle it? Â Certainly I could reset the value after each ds.AcceptChanges, but this doesn't seem real elegant.
Also, are there any other situations I should be aware of that would reset the enabled property?
Any information regarding this situation is much appreciated.
Thanks,
Chris
Depending on the situation, I either want to enable or disable the Delete button on the navigation bar (the red "X").
However, I am having problems getting this to work. Â I have narrowed it down to a situation where it appears certain things reset the enabled property.
For instance, if I have the form open and the delete button is disabled, if I do an AcceptChanges on the dataset, the BindingNavigator delete button resets to be enabled. Â If I add a line immediately after the ds.AcceptChanges to reset the button to be disabled, it works fine.
My question is why does this happen? Â What would be the best way to handle it? Â Certainly I could reset the value after each ds.AcceptChanges, but this doesn't seem real elegant.
Also, are there any other situations I should be aware of that would reset the enabled property?
Any information regarding this situation is much appreciated.
Thanks,
Chris
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks. Â What you said does make sense. Â After reading what you said it triggered a different idea for me. Â In my actual program, I'm wanting to enable/disable based on whether a specific field is blank. Â So what I did was put code in the Paint event of the delete button and it works great.
Here's my code:
  Private Sub BindingNavigatorDeleteItem _Paint(ByV al sender As Object, ByVal e As System.Windows.Forms.Paint EventArgs) Handles BindingNavigatorDeleteItem .Paint
    If txtClientName.Text.Trim = "" Then
      BindingNavigatorDeleteItem .Enabled = True
    Else
      BindingNavigatorDeleteItem .Enabled = False
    End If
  End Sub
Here's my code:
  Private Sub BindingNavigatorDeleteItem
    If txtClientName.Text.Trim = "" Then
      BindingNavigatorDeleteItem
    Else
      BindingNavigatorDeleteItem
    End If
  End Sub
Hi,
I do a lot of enabling and disabling of contols and most of the time everything works fine. Â However when it does not I also put my code in the paint event.
Here is a little sample Code.
Good luck.
Kip
 Private Sub tblOrderHeaderBindingNavig ator_Paint (ByVal sender As Object, ByVal e As System.Windows.Forms.Paint EventArgs) Handles TblOrderHeaderBindingNavig ator.Paint
    If Me.btnHSave110.Enabled Then
      Me.grdHeader001.Enabled = False
      'Next Line example
    end if
end sub
I do a lot of enabling and disabling of contols and most of the time everything works fine. Â However when it does not I also put my code in the paint event.
Here is a little sample Code.
Good luck.
Kip
 Private Sub tblOrderHeaderBindingNavig
    If Me.btnHSave110.Enabled Then
      Me.grdHeader001.Enabled = False
      'Next Line example
    end if
end sub
ASKER
Option Strict On
Option Explicit On
Public Class frmInvoiceEntry
  Inherits System.Windows.Forms.Form
  Friend WithEvents ds As System.Data.DataSet
  Friend WithEvents dtServiceHeader As System.Data.DataTable
  Friend WithEvents colSHClient As System.Data.DataColumn
  Friend WithEvents colSHClientName As System.Data.DataColumn
  Friend WithEvents txtClientName As System.Windows.Forms.TextB
  Friend WithEvents txtClient As System.Windows.Forms.TextB
  Friend WithEvents btnDisableThenAccept As System.Windows.Forms.Butto
  Friend WithEvents btnAcceptThenDisable As System.Windows.Forms.Butto
  Friend WithEvents masterBindingSource As System.Windows.Forms.Bindi
  Friend WithEvents BindingNavigator1 As System.Windows.Forms.Bindi
  Friend WithEvents BindingNavigatorAddNewItem
  Friend WithEvents BindingNavigatorCountItem As System.Windows.Forms.ToolS
  Friend WithEvents BindingNavigatorDeleteItem
  Friend WithEvents BindingNavigatorMoveFirstI
  Friend WithEvents BindingNavigatorMovePrevio
  Friend WithEvents BindingNavigatorSeparator As System.Windows.Forms.ToolS
  Friend WithEvents BindingNavigatorPositionIt
  Friend WithEvents BindingNavigatorSeparator1
  Friend WithEvents BindingNavigatorMoveNextIt
  Friend WithEvents BindingNavigatorMoveLastIt
  Friend WithEvents BindingNavigatorSeparator2
#Region "Â Windows Form Designer generated code "
  Public Sub New()
    MyBase.New()
    'This call is required by the Windows Form Designer.
    InitializeComponent()
    'Add any initialization after the InitializeComponent() call
  End Sub
  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub
  'Required by the Windows Form Designer
  Private components As System.ComponentModel.ICon
  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer. Â
  'Do not modify it using the code editor.
  <System.Diagnostics.Debugg
    Me.components = New System.ComponentModel.Cont
    Dim resources As System.ComponentModel.Comp
    Me.masterBindingSource = New System.Windows.Forms.Bindi
    Me.ds = New System.Data.DataSet
    Me.dtServiceHeader = New System.Data.DataTable
    Me.colSHClient = New System.Data.DataColumn
    Me.colSHClientName = New System.Data.DataColumn
    Me.BindingNavigator1 = New System.Windows.Forms.Bindi
    Me.BindingNavigatorCountIt
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorPositio
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorAddNewI
    Me.txtClientName = New System.Windows.Forms.TextB
    Me.btnDisableThenAccept = New System.Windows.Forms.Butto
    Me.btnAcceptThenDisable = New System.Windows.Forms.Butto
    Me.txtClient = New System.Windows.Forms.TextB
    CType(Me.masterBindingSour
    CType(Me.ds, System.ComponentModel.ISup
    CType(Me.dtServiceHeader, System.ComponentModel.ISup
    CType(Me.BindingNavigator1
    Me.BindingNavigator1.Suspe
    Me.SuspendLayout()
    '
    'masterBindingSource
    '
    Me.masterBindingSource.Dat
    Me.masterBindingSource.Dat
    Me.masterBindingSource.Sor
    '
    'ds
    '
    Me.ds.DataSetName = "NewDataSet"
    Me.ds.Tables.AddRange(New System.Data.DataTable() {Me.dtServiceHeader})
    '
    'dtServiceHeader
    '
    Me.dtServiceHeader.Columns
    Me.dtServiceHeader.Constra
    Me.dtServiceHeader.TableNa
    '
    'colSHClient
    '
    Me.colSHClient.Caption = "Client"
    Me.colSHClient.ColumnName = "Client"
    Me.colSHClient.DefaultValu
    '
    'colSHClientName
    '
    Me.colSHClientName.ColumnN
    '
    'BindingNavigator1
    '
    Me.BindingNavigator1.AddNe
    Me.BindingNavigator1.Bindi
    Me.BindingNavigator1.Count
    Me.BindingNavigator1.Delet
    Me.BindingNavigator1.Dock = System.Windows.Forms.DockS
    Me.BindingNavigator1.Items
    Me.BindingNavigator1.Locat
    Me.BindingNavigator1.MoveF
    Me.BindingNavigator1.MoveL
    Me.BindingNavigator1.MoveN
    Me.BindingNavigator1.MoveP
    Me.BindingNavigator1.Name = "BindingNavigator1"
    Me.BindingNavigator1.Posit
    Me.BindingNavigator1.Size = New System.Drawing.Size(222, 25)
    Me.BindingNavigator1.TabIn
    Me.BindingNavigator1.Text = "BindingNavigator1"
    '
    'BindingNavigatorCountItem
    '
    Me.BindingNavigatorCountIt
    Me.BindingNavigatorCountIt
    Me.BindingNavigatorCountIt
    Me.BindingNavigatorCountIt
    '
    'BindingNavigatorDeleteIte
    '
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorDeleteI
    Me.BindingNavigatorDeleteI
    '
    'BindingNavigatorMoveFirst
    '
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMoveFir
    Me.BindingNavigatorMoveFir
    '
    'BindingNavigatorMovePrevi
    '
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorMovePre
    Me.BindingNavigatorMovePre
    '
    'BindingNavigatorSeparator
    '
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorSeparat
    '
    'BindingNavigatorPositionI
    '
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    Me.BindingNavigatorPositio
    '
    'BindingNavigatorSeparator
    '
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorSeparat
    '
    'BindingNavigatorMoveNextI
    '
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveNex
    Me.BindingNavigatorMoveNex
    '
    'BindingNavigatorMoveLastI
    '
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorMoveLas
    Me.BindingNavigatorMoveLas
    '
    'BindingNavigatorSeparator
    '
    Me.BindingNavigatorSeparat
    Me.BindingNavigatorSeparat
    '
    'BindingNavigatorAddNewIte
    '
    Me.BindingNavigatorAddNewI
    Me.BindingNavigatorAddNewI
    Me.BindingNavigatorAddNewI
    Me.BindingNavigatorAddNewI
    Me.BindingNavigatorAddNewI
    Me.BindingNavigatorAddNewI
    '
    'txtClientName
    '
    Me.txtClientName.DataBindi
    Me.txtClientName.Location = New System.Drawing.Point(12, 83)
    Me.txtClientName.Name = "txtClientName"
    Me.txtClientName.Size = New System.Drawing.Size(222, 20)
    Me.txtClientName.TabIndex = 2
    '
    'btnDisableThenAccept
    '
    Me.btnDisableThenAccept.Lo
    Me.btnDisableThenAccept.Na
    Me.btnDisableThenAccept.Si
    Me.btnDisableThenAccept.Ta
    Me.btnDisableThenAccept.Te
    Me.btnDisableThenAccept.Us
    '
    'btnAcceptThenDisable
    '
    Me.btnAcceptThenDisable.Lo
    Me.btnAcceptThenDisable.Na
    Me.btnAcceptThenDisable.Si
    Me.btnAcceptThenDisable.Ta
    Me.btnAcceptThenDisable.Te
    Me.btnAcceptThenDisable.Us
    '
    'txtClient
    '
    Me.txtClient.DataBindings.
    Me.txtClient.Location = New System.Drawing.Point(12, 56)
    Me.txtClient.Name = "txtClient"
    Me.txtClient.Size = New System.Drawing.Size(76, 20)
    Me.txtClient.TabIndex = 1
    '
    'frmInvoiceEntry
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.AutoScroll = True
    Me.ClientSize = New System.Drawing.Size(398, 112)
    Me.Controls.Add(Me.btnAcce
    Me.Controls.Add(Me.btnDisa
    Me.Controls.Add(Me.Binding
    Me.Controls.Add(Me.txtClie
    Me.Controls.Add(Me.txtClie
    Me.Name = "frmInvoiceEntry"
    Me.Text = "Invoice Entry"
    CType(Me.masterBindingSour
    CType(Me.ds, System.ComponentModel.ISup
    CType(Me.dtServiceHeader, System.ComponentModel.ISup
    CType(Me.BindingNavigator1
    Me.BindingNavigator1.Resum
    Me.BindingNavigator1.Perfo
    Me.ResumeLayout(False)
    Me.PerformLayout()
  End Sub
#End Region
  Private Sub frmInvoiceEntry_Load(ByVal
    ds.Tables(0).Rows.Add("MIC
    ds.Tables(0).Rows.Add("IBM
    ds.Tables(0).Rows.Add("APL
    BindingNavigatorDeleteItem
  End Sub
  Private Sub btnDisableThenAccept_Click
    BindingNavigatorDeleteItem
    ds.AcceptChanges()
  End Sub
  Private Sub btnAcceptThenDisable_Click
    ds.AcceptChanges()
    BindingNavigatorDeleteItem
  End Sub
End Class