DockableWindow problem with Focus

DockableWindow problem with Focus

Anonymous
Not applicable
611 Views
2 Replies
Message 1 of 3

DockableWindow problem with Focus

Anonymous
Not applicable
Hi, I'm working with a dockable window and discovered a problem with focusing on the text box. When clicking a tree node, the name is written in the textbox and it shall be focused and all selected. Unfortunately the textbox doesn't keep the focus. I tried already with the debugger. There I discovered that the focus is really set to the textbox, but then it got lost immediately. Attached Is a picture of my dockable window and the code. I hope you can help me. Public Class Form1 Private invApp As Inventor.Application Private activeDoc As Inventor.AssemblyDocument Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load invApp = InventorAddInDWTest1.StandardAddInServer.m_inventorApplication Label1.Text = "TextBox1:" End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Try If invApp.ActiveDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then activeDoc = invApp.ActiveDocument Dim topNode As New TreeNode(activeDoc.DisplayName) For Each occ As ComponentOccurrence In activeDoc.ComponentDefinition.Occurrences Dim node As New TreeNode(occ.Name) topNode.Nodes.Add(node) Next TreeView1.Nodes.Add(topNode) TreeView1.ExpandAll() Else TreeView1.Nodes.Clear() activeDoc = Nothing TextBox1.Clear() Exit Sub End If Catch ex As Exception End Try End Sub Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick Try Dim node As TreeNode = e.Node TextBox1.Text = node.Text TextBox1.Focus() Catch ex As Exception End Try End Sub Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus Label1.Text = "TextBox1: Focus" TextBox1.SelectAll() End Sub Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus Label1.Text = "TextBox1: Focus lost" End Sub End Class Thanks Andreas
0 Likes
Accepted solutions (1)
612 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Sorry here is the code and picture again.

I had some problems to post it with Firefox

 

Public Class Form1

    Private invApp As Inventor.Application
    Private activeDoc As Inventor.AssemblyDocument

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        invApp = InventorAddInDWTest1.StandardAddInServer.m_inventorApplication
        Label1.Text = "TextBox1:"

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Try

            If invApp.ActiveDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
                activeDoc = invApp.ActiveDocument

                Dim topNode As New TreeNode(activeDoc.DisplayName)

                For Each occ As ComponentOccurrence In activeDoc.ComponentDefinition.Occurrences
                    Dim node As New TreeNode(occ.Name)
                    topNode.Nodes.Add(node)
                Next

                TreeView1.Nodes.Add(topNode)
                TreeView1.ExpandAll()

            Else
                TreeView1.Nodes.Clear()
                activeDoc = Nothing
                TextBox1.Clear()
                Exit Sub
            End If

        Catch ex As Exception

        End Try

    End Sub


    Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
        Try
            Dim node As TreeNode = e.Node
            TextBox1.Text = node.Text

            TextBox1.Focus()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
        Label1.Text = "TextBox1: Focus"
        TextBox1.SelectAll()
    End Sub



    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        Label1.Text = "TextBox1: Focus lost"
    End Sub
End Class
0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Hi,

I could find a solution:

 

This is not a matter of the DockableWindow itself, but of the TreeViewControl in general. I added the code below to focus the textbox after selecting a tree node.

 

Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
        Me.TreeView1.BeginInvoke(New MethodInvoker(AddressOf FocusOnTextbox))
End Sub

Private Sub FocusOnTextbox()
        TextBox1.Focus()
        TextBox1.SelectAll()
End Sub

I hope this helps somebody else.

0 Likes