I re-read the documentation for BindingNavigator and found out what I was doing wrong.
I should've overridden the AddStandardItems method and insert the button there.
So this is the re-done code and it works 100%.
So, as usually, there are many ways to skin a catvb.net Code:
Public Class BindingNavigatorEx Inherits System.Windows.Forms.BindingNavigator Private WithEvents _CloseForm As ToolStripItem = Nothing Public Property CloseFormItem() As ToolStripItem Get Return _CloseForm End Get Set(ByVal value As ToolStripItem) _CloseForm = value End Set End Property Public Sub New() MyBase.New() End Sub Public Overrides Sub AddStandardItems() Me._CloseForm = New ToolStripButton("Close") Me._CloseForm.Name = "ToolStripButtonCloseForm" Me.Items.Add(Me._CloseForm) 'Add a separator Dim separator As New ToolStripSeparator() Me.Items.Add(separator) MyBase.AddStandardItems() End Sub Private Sub _CloseForm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _CloseForm.Click If Me.DesignMode = False Then 'Find the outer most parent container control and trycast it to a form 'and call the close method on that form Dim parent As Form = Nothing Dim child As Control = Me Dim ctrl As Control = Me.Parent Do Until ctrl Is Nothing child = ctrl ctrl = ctrl.Parent Loop parent = TryCast(child, Form) If parent IsNot Nothing Then parent.Close() End If End If End Sub End Class![]()




Reply With Quote