This project is read-only.

TextBoxButton - button click event

Mar 23, 2009 at 2:06 PM
Edited Mar 23, 2009 at 2:06 PM
What event is fired when "SourceGrid.Cells.Editors.TextBoxButton" button is clicked?

What I am trying to do is display a "System.Windows.Forms.ToolStripDropDown" that contains a user control. I have a test project that is working successfully (based on the example in frm3). However it is simple and only is able to return one result (Control.Value = _panel.GetResult). That is fine but I would like to be able to do more work in the user control but I can't seem to figure it out.  Ideally, when the text box button is pressed I would like to pass an object to the user control before it is displayed. Any ideas?


Here is my editor code:

Public Class CellEditorTextButton
    Inherits SourceGrid.Cells.Editors.TextBoxButton

#Region "Private Class Variables"
    Private _panel As PopUpPanel
#End Region

#Region "Constructor"
    Public Sub New()
        MyBase.New(GetType(String))

        Me.EditableMode = SourceGrid.EditableMode.SingleClick
        AddHandler Control.DialogOpen, AddressOf Control_DialogOpen
    End Sub


    Private Sub Control_DialogOpen(ByVal sender As Object, ByVal e As EventArgs)
        'when the dialog is opened this event will be fired

        If sender Is Nothing Then Return

        Dim textBoxButton As DevAge.Windows.Forms.DevAgeTextBoxButton = DirectCast(sender, DevAge.Windows.Forms.DevAgeTextBoxButton)

        'Dim btn As Button = DirectCast(sender, Button)
        Dim clientRect As Rectangle = textBoxButton.Parent.RectangleToScreen(textBoxButton.Bounds) 'convert the bounds of the control to a rectangle of screen coordinates

        Dim p As New PopupItem
        If _panel Is Nothing Then
            _panel = New PopUpPanel(p)
            AddHandler _panel.Closed, AddressOf Panel_Close
        Else
            'add a call that will clear the contents of the panel out...
        End If
        _panel.Show(New Point(clientRect.Left, clientRect.Bottom))
    End Sub

    Private Sub Panel_Close(ByVal sender As Object, ByVal e As ToolStripDropDownClosedEventArgs)
        Control.Value = _panel.GetResult
    End Sub
#End Region

#Region "Protected overrides..."
    'http://www.devage.com/Forum/ViewTopic.aspx?id=a3ff979d999447d7a09dee57772d6724
    'don't allow the user to edit the text in the box
    Protected Overrides Sub OnStartingEdit(ByVal cellContext As SourceGrid.CellContext, ByVal editorControl As System.Windows.Forms.Control)
        MyBase.OnStartingEdit(cellContext, editorControl)
        Control.TextBox.ReadOnly = True
    End Sub
#End Region
End Class

Here is the ToolStripDropDown class that I am using to encapsulate the user control that I want to display:
Public Class PopUpPanel
    Inherits System.Windows.Forms.ToolStripDropDown

'Based on c# code from 'http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c15391__2/

#Region "Private Class Variables"
    Private _content As Control
    Private _host As ToolStripControlHost
#End Region

#Region "Constructor"
    Public Sub New(ByVal content As Control)
        MyBase.New()

        If content Is Nothing Then Throw New ArgumentNullException("content")

        With Me
            .AutoSize = False
            .DoubleBuffered = True
            .ResizeRedraw = True

            _content = content
            _host = New System.Windows.Forms.ToolStripControlHost(content)

            .Padding = Padding.Empty
            _host.Padding = Padding.Empty
            _host.Margin = Padding.Empty
            Margin = Padding.Empty

            'Positioning and Sizing
            content.MinimumSize = content.Size
            .MinimumSize = content.MinimumSize
            content.MinimumSize = content.Size
            .MaximumSize = content.Size
            .Size = content.Size
            content.Location = Point.Empty

            ''Add the host to the list
            .Items.Add(Me._host)
        End With
    End Sub
#End Region


Public Function GetResult() As String
    If _content Is Nothing Then Return String.Empty

    Return DirectCast(_content, PopupItem).txtDeckCount.Text

End Function

#Region "Overridden methods..."
    Protected Overrides Sub OnClosed(ByVal e As System.Windows.Forms.ToolStripDropDownClosedEventArgs)
        MyBase.OnClosed(e)

        'raise an event to let the caller know that the tooltip is closed

    End Sub
#End Region

End Class

Mar 24, 2009 at 2:24 PM
Hi all, I solved my own problem. Just need to think about it.

What I did was raise an event before the drop down panel was displayed and passed a reference to the user control that was going to be displayed.