Home › Forums › WinForms controls › Xceed Grid for WinForms › Getting character number of winTextBox from QueryInputKey event
-
AuthorPosts
-
#16772 |
Hi,
I want to caculate the lenght of a word in a cell as the user inputs each character. The below code works fine if they are typing letters in. The problem is if the user selects some of the text and presses the backspace button to delete it. The e.keydata has a value of “back” which messes things up. I could check for the “backspace” key, but I still do not know how many characters they have deleted because the: DirectCast(e.Control, WinTextBox).TextBoxArea.Text – will only give me the value before they delete characters.vb.net please.
AddHandler xg.Columns(4).CellEditorManager.QueryInputKey, AddressOf InputKey
Private Sub InputKey(ByVal sender As Object, ByVal e As Xceed.Grid.Editors.QueryEditorInputKeyEventArgs)
Dim txt, t As Stringtxt = DirectCast(e.Control, WinTextBox).TextBoxArea.Text
If Char.IsLetter(e.KeyData.ToString) Then
txt = txt & e.KeyData.ToString
End IftsslMess.Text = “Text length: ” & Len(txt))
End Sub
Thanks in advance.
Troy.Imported from legacy forums. Posted by troy@querytool.com (had 548 views)
We suggest you use the TextChanged event on the TextBoxArea instead, and get the text length in the event handler.
e.g.:
//at Form_Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler GridControl1.Columns( 0 ).CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControlEnd Sub
//Event handlers :
Private Sub CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
Dim editor as Xceed.Editors.WinTextBox = CType( e.Control, Xceed.Editors.WinTextBox)
AddHandler editor.TextBoxArea.TextChanged, AddressOf editor_TextChangedEnd Sub
Private Sub CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
Dim editor as Xceed.Editors.WinTextBox = CType( e.Control, Xceed.Editors.WinTextBox)
‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
RemoveHandler editor.TextBoxArea.TextChanged, AddressOf editor_TextChanged
End SubPrivate sub editor_TextChanged(ByVal sender As System.Object, ByVal e As EventArgs )
Dim value as String = CType( sender, TextBoxArea ).TextLength.ToString
End SubImported from legacy forums. Posted by André (had 580 views)
-
AuthorPosts
- You must be logged in to reply to this topic.