Results 1 to 6 of 6

Thread: [RESOLVED] Subclass BindingNavigator - Strange behavior

Threaded View

  1. #1

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Resolved [RESOLVED] Subclass BindingNavigator - Strange behavior

    Hello all,

    One of the VBF member was asking how to add a close button on the BindingNavigator control once and reuse it on all other forms, so I try to create a custom bindingnavigator class that inherits the BindingNavigator class.
    Below is the inherited class:
    vb.net Code:
    1. Public Class BindingNavigatorEx
    2.     Inherits System.Windows.Forms.BindingNavigator
    3.  
    4.     Public Sub New()
    5.         MyBase.New()
    6.  
    7.         'Add the closeform button
    8.         Dim closeButton As New ToolStripButton("Close", Nothing, New EventHandler(AddressOf CloseForm_OnClick))
    9.         Me.Items.Add(closeButton)
    10.  
    11.         'Add a separator
    12.         Dim separator As New ToolStripSeparator()
    13.         separator.Size = New System.Drawing.Size(6, 25)
    14.         Me.Items.Add(separator)
    15.  
    16.     End Sub
    17.  
    18.     Private Sub CloseForm_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
    19.         'Find the outer most parent container control and trycast it to a form
    20.         'and call the close method on that form
    21.         Dim parent As Form = Nothing
    22.         Dim child As Control = Me
    23.         Dim ctrl As Control = Me.Parent
    24.         Do Until ctrl Is Nothing
    25.             child = ctrl
    26.             ctrl = ctrl.Parent
    27.         Loop
    28.         parent = TryCast(child, Form)
    29.         If parent IsNot Nothing Then
    30.             parent.Close()
    31.         End If
    32.     End Sub
    33. End Class
    The thing that I can't figure out is that it looks OK in design mode, but at run time, the custom binding navigator shows 2 "Close" buttons. Only one of them will close the form when clicked, the other one doesn't function. See the attached image.
    Any ideas?
    Last edited by stanav; Sep 11th, 2009 at 08:19 AM.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width