Validating Textbox

Add-in Express™ Support Service
That's what is more important than anything else

Validating Textbox
How to keep the focus on the textbox when validating is cancelled? 
Ingrid Kellerer




Posts: 18
Joined: 2011-03-15
Hi,

I am using a Word Advanced Taskpane with a texbox and several comboboxes. (VB.NET with VS 2010/Word 2010, latest Addin-Express version)

Furthermore I am triggering the me.ADXLeave-Event to run some routines whenever the tp looses the focus to the document.

What I'd like to implement:
As not all entries are allowed for the textbox, I am checking the modified text during the textbox-validating-event.
If the entry doesn't match the rule, I'd like to highlight the wrong text and have the focus set to the textbox, so that the user is forced to make the correction.

What I have done:
 
Private Sub tbName_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles tbName.Validating
        If tbName.Text.IndexOf("_") > 0 Then
            MessageBox.Show(My.Messages.BBAdminWizard_UnderscoreNotAllowedForBBName, "BBAdminWizard", MessageBoxButtons.OK, MessageBoxIcon.Error)
            tbName.Focus()
            tbName.SelectAll()
            e.Cancel = True
        End If


What happens:
Although I am using the tab-key to jump to the next tp-control and e.cancel is set to true during the validating-event, ADXLeave-event is triggered and focus is set to the document instead of staying within the textbox control.

What is the correct way to achieve the behaviour described above.

Best regards,
Ingrid Kellerer
Posted 08 Feb, 2013 05:07:08 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Ingrid,

I cannot confirm the issue. I've tested your code in Word 2010-2013 32bit with no problem; I used this code in ADXLeave:

tbName.Text = "sometext"


I suppose that the problem occurs in the ADXLeave event. Can you please try to comment out your code handling this event and check if the issue is reproducible?


Andrei Smolin
Add-in Express Team Leader
Posted 08 Feb, 2013 06:24:38 Top