Setting focus to a particular control based on TabOrder on TabOrderController


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I have a subclass of groupbox I want to use for my grids. For reasons shown in another thread, if my grid, in a groupbox, is on a tabpage, as I leave the groupbox it is getting a little stupid about setting focus to the next control in the taborder (using a tabordercontroller) Right now I am manually setting focus to a control, by name. I have made this generic



Imports System.Windows.Forms



Public Class GridGroupbox

Inherits MicroFour.StrataFrame.UI.Windows.Forms.GroupBox



Private _NextControl As String

Public Property NextControl() As String

Get

Return _NextControl

End Get

Set(ByVal value As String)

_NextControl = value

End Set

End Property





Private Sub MyGroupbox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter

Me.Controls(0).Focus()

End Sub



Private Sub GridGroupbox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave

If Not String.IsNullOrEmpty(Me.NextControl()) Then

Dim myform As Form = Me.FindForm()

Dim nc() As Control

nc = myform.Controls.Find(Me.NextControl, True)

nc(0).Focus()

End If

End Sub

End Class




First, is there a better way to get an object reference to a control when I have a string that represents the name of that control ?



Second, is a there a generic way I can say "If the this control has a taborder property for a TOcontroller, set focus to the control which has a taborder property = me.taborder + 1



I assume I can start with the form, find the TabOrderController and then find the control reference in its collection to the next control ? Or is there something better ?



This is fun BigGrin
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I haven't tried this, but taking a look at the tab controller, I think I'd try out the GetNextFocusableControl method of the controller. Then to make this more usable, I'd add a property to your groupbox to set the controller.



Private _controller As TabController

Public Property Controller As TabController

  Get

    Return _controller

  End Get

  Set(value As TabController)

    _controller = value

  End Set

End Property



Private Sub GridGroupbox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave

  Me.Controller.GetNextFocusableControl(Me).Focus()

End Sub





The GetNextFocusableControl method returns the next enabled, visible control in tab order, as defined by the tab controller, relative to the control passed in. This can get confusing, so likely you'll need to tweek what control is used (likely it won't be "Me", but one of the controls within the group box).



Also, using the technique your using, rather than store the control name (which might change), make the property of type Control. Then you can select the control from those on the form.



Private _NextControl As Control

Public Property NextControl() As Control

  Get

    Return _NextControl

  End Get

  Set(ByVal value As Control)

    _NextControl = value

  End Set

End Property




Now you can use Me.NextControl.Focus() to set focus on that control. Have fun playing with this. BigGrin
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Hey Greg



Actually in the iteration I posted to Ivan I have a property ( string) in the groupbox for the name of the next control. ( I see the advantage of make it of type control - at the time I was just geeked out on figuring out how to get an object reference to the control from the name as string. As we've often said you find some of the best stuff while looking for something else and that led to finding out a lot about finding stuff )



The idea of a tabcontroller property is good and was in fact using the getnextvisiblecontrol but I'd still like to know how one can find an object reference to a component. If i have a project of controls and i want to put code in there to find a component of the form it is dropped on if it exists. I got very close with .gettype().getproperty() to find if the property was there but that only told me if the property existed. i still couldn't figure out how to actually refer to it. Kept telling me it didn't refer to an instance of an object (out of office now - will post code I tried tomorrow )



When the components are loaded in the componentmodel they seem to go into me.components in the form, but at run time me.compenents.components is nothing.



Oh well, it's been a 16 hour day. Like a kid with ADD and OCD who has already had too much sugar and has spent the day in a candy store ...Tongue







Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Charles.

Not sure this is what you are looking for, but I use this method to find out if a component is dropped on the form, and then make reference to a method inside of it.

    ''' <summary>
    ''' Recursively checks all form's controls
    ''' </summary>
    ''' <param name="currentControl"></param>
    ''' <remarks></remarks>
    Private Sub RecursivelyIterateControls(ByVal currentControl As Control, _
                                           ByVal action As String)
        For Each ctrl As Control In currentControl.Controls
            '-- if UltraGridOffisys, take care of action
            If TypeOf ctrl Is Offisys.ProFilmeNET.UI.UltraGridOffisys Then
                Select Case action
                    Case "SaveGridLayout"
                        '-- save grid layout and reset its Datasource
                        CType(ctrl, Offisys.ProFilmeNET.UI.UltraGridOffisys).SaveGridLayoutAndLeave(CType(ctrl, Infragistics.Win.UltraWinGrid.UltraGrid))
                    Case "ResetGridLayout"
                        '-- reset grid layout to form's original
                        CType(ctrl, Offisys.ProFilmeNET.UI.UltraGridOffisys).ResetGridLayout(CType(ctrl, Infragistics.Win.UltraWinGrid.UltraGrid))
                End Select
            Else
                If ctrl.Controls.Count > 0 Then
                    RecursivelyIterateControls(ctrl, action)
                End If
            End If
        Next
    End Sub


Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
That's a very handy piece of code and I'm sure I will use it, but see my reply in the other thread. The problem I am seeing is that it looks to me like a TabOrderController is a component and not a contorl and is not in the controls collection. I see the components being added to Me.Components in the form designer but Me.components shows nothing at run-time (unless I'm really looking in the wrong place ... )

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
I posted something on the other thread, see if it helps.

http://forum.strataframe.net/FindPost27321.aspx

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search