CommandBarTextBox Events

4 posts, 1 answers
  1. Ryan
    Ryan avatar
    22 posts
    Member since:
    Oct 2010

    Posted 29 Nov 2010 Link to this post

    Good Day/Evening,

    I've been using the new CommandBar which looks awesome I think but I have a problem with the CommandBarTextbox, I've put the CommandBarTextbox in the CommandBar and added the following code below but the events do not get hit at all. Any help would be much appreciated.

    Public Sub New()
     
        ' This call is required by the designer.
        InitializeComponent()
     
        ' Add any initialization after the InitializeComponent() call.
        AddHandler txtMyCommandTextBox.KeyDown, AddressOf txtMyCommandTextBox_KeyDown
        AddHandler txtMyCommandTextBox.KeyPress, AddressOf txtMyCommandTextBox_KeyPress
        AddHandler txtMyCommandTextBox.KeyUp, AddressOf txtMyCommandTextBox_KeyUp
     
    End Sub
     
    Private Sub txtMyCommandTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        RadMessageBox.Show(e.KeyCode)
    End Sub
     
    Private Sub txtMyCommandTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        RadMessageBox.Show(e.KeyChar)
    End Sub
     
    Private Sub txtMyCommandTextBox_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        RadMessageBox.Show(e.KeyCode)
    End Sub
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 29 Nov 2010 Link to this post

    Hello Ryan,

    I've recently reported this as an issue. You need to handle the events on the TextBoxItem instead. Have a look at the code below

    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls
      
    Public Class Form1
      
        Private WithEvents m_TextBoxItem As RadTextBoxItem
      
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.CommandBarTextBox1.Text = ""
            Me.CommandBarTextBox1.TextBoxElement.TextBoxItem.MaxLength = 3
            m_TextBoxItem = Me.CommandBarTextBox1.TextBoxElement.TextBoxItem
      
        End Sub
      
        ''' <summary>
        ''' This fires correctly
        ''' </summary>
        Private Sub CommandBarTextBox1TextBoxItem_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_TextBoxItem.TextChanged
            MessageBox.Show("m_TextBoxItem " & Me.CommandBarTextBox1.Text)
        End Sub
      
        ''' <summary>
        ''' This fires correctly
        ''' </summary>
        Private Sub CommandBarTextBox1TextBoxItem_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles m_TextBoxItem.KeyDown
            MessageBox.Show("m_TextBoxItem " & e.KeyValue.ToString())
        End Sub
      
        ''' <summary>
        ''' This only fires on initial load
        ''' </summary>
        Private Sub CommandBarTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CommandBarTextBox1.TextChanged
            MessageBox.Show("CommandBarTextBox1 " & Me.CommandBarTextBox1.Text)
        End Sub
      
        ''' <summary>
        ''' This doesn't fire
        ''' </summary>
        Private Sub CommandBarTextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles CommandBarTextBox1.KeyDown
            MessageBox.Show("CommandBarTextBox1 " & e.KeyValue.ToString())
        End Sub
    End Class

    hope this helps but let me know if you have any questions
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ryan
    Ryan avatar
    22 posts
    Member since:
    Oct 2010

    Posted 29 Nov 2010 Link to this post

    Thanks for the solution, works perfectly.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 29 Nov 2010 Link to this post

    Glad to have been able to help
    Richard
Back to Top