﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Setting focus to a particular control based on TabOrder on TabOrderController</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 08 Sep 2026 22:21:49 GMT</lastBuildDate><ttl>20</ttl><item><title>Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27295.aspx</link><description>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&lt;br&gt;
&lt;br&gt;
[codesnippet]Imports System.Windows.Forms&lt;br&gt;
&lt;br&gt;
Public Class GridGroupbox&lt;br&gt;
    Inherits MicroFour.StrataFrame.UI.Windows.Forms.GroupBox&lt;br&gt;
&lt;br&gt;
    Private _NextControl As String&lt;br&gt;
    Public Property NextControl() As String&lt;br&gt;
        Get&lt;br&gt;
            Return _NextControl&lt;br&gt;
        End Get&lt;br&gt;
        Set(ByVal value As String)&lt;br&gt;
            _NextControl = value&lt;br&gt;
        End Set&lt;br&gt;
    End Property&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
    Private Sub MyGroupbox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter&lt;br&gt;
        Me.Controls(0).Focus()&lt;br&gt;
    End Sub&lt;br&gt;
&lt;br&gt;
    Private Sub GridGroupbox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave&lt;br&gt;
        If Not String.IsNullOrEmpty(Me.NextControl()) Then&lt;br&gt;
            Dim myform As Form = Me.FindForm()&lt;br&gt;
            Dim nc() As Control&lt;br&gt;
            nc = myform.Controls.Find(Me.NextControl, True)&lt;br&gt;
            nc(0).Focus()&lt;br&gt;
        End If&lt;br&gt;
    End Sub&lt;br&gt;
End Class[/codesnippet]&lt;br&gt;
&lt;br&gt;
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 ?  &lt;br&gt;
&lt;br&gt;
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&lt;br&gt;
&lt;br&gt;
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 ?  &lt;br&gt;
&lt;br&gt;
This is fun :D</description><pubDate>Mon, 07 Jun 2010 13:23:21 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27322.aspx</link><description>I posted something on the other thread, see if it helps.&lt;/P&gt;&lt;P&gt;&lt;A href="http://forum.strataframe.net/FindPost27321.aspx"&gt;http://forum.strataframe.net/FindPost27321.aspx&lt;/A&gt;</description><pubDate>Mon, 07 Jun 2010 13:23:21 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27319.aspx</link><description>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 ... ) &lt;br&gt;</description><pubDate>Mon, 07 Jun 2010 12:33:50 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27313.aspx</link><description>Hi Charles.&lt;/P&gt;&lt;P&gt;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&amp;nbsp;it.&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' Recursively checks all form's controls&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;param name="currentControl"&amp;gt;&amp;lt;/param&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub RecursivelyIterateControls(ByVal currentControl As Control, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ByVal action As String)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each ctrl As Control In currentControl.Controls&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- if UltraGridOffisys, take care of action&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If TypeOf ctrl Is Offisys.ProFilmeNET.UI.UltraGridOffisys Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select Case action&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case "SaveGridLayout"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- save grid layout and reset its Datasource&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CType(ctrl, Offisys.ProFilmeNET.UI.UltraGridOffisys).SaveGridLayoutAndLeave(CType(ctrl, Infragistics.Win.UltraWinGrid.UltraGrid))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case "ResetGridLayout"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- reset grid layout to form's&amp;nbsp;original&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CType(ctrl, Offisys.ProFilmeNET.UI.UltraGridOffisys).ResetGridLayout(CType(ctrl, Infragistics.Win.UltraWinGrid.UltraGrid))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Select&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If ctrl.Controls.Count &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RecursivelyIterateControls(ctrl, action)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/P&gt;&lt;P&gt;[/codesnippet]</description><pubDate>Mon, 07 Jun 2010 09:14:19 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27303.aspx</link><description>Hey Greg&lt;br&gt;
&lt;br&gt;
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  )&lt;br&gt;
&lt;br&gt;
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 )&lt;br&gt;
&lt;br&gt;
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.  &lt;br&gt;
&lt;br&gt;
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 ...:P&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 02 Jun 2010 22:40:19 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Setting focus to a particular control based on TabOrder on TabOrderController</title><link>http://forum.strataframe.net/FindPost27299.aspx</link><description>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.&lt;br&gt;
&lt;br&gt;
[codesnippet]Private _controller As TabController&lt;br&gt;
Public Property Controller As TabController&lt;br&gt;
&amp;nbsp;&amp;nbsp;Get&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return _controller&lt;br&gt;
&amp;nbsp;&amp;nbsp;End Get&lt;br&gt;
&amp;nbsp;&amp;nbsp;Set(value As TabController)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_controller = value&lt;br&gt;
&amp;nbsp;&amp;nbsp;End Set&lt;br&gt;
End Property&lt;br&gt;
&lt;br&gt;
Private Sub GridGroupbox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave&lt;br&gt;
&amp;nbsp;&amp;nbsp;Me.Controller.GetNextFocusableControl(Me).Focus()&lt;br&gt;
End Sub&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
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).  &lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
[codesnippet]Private _NextControl As Control&lt;br&gt;
Public Property NextControl() As Control&lt;br&gt;
&amp;nbsp;&amp;nbsp;Get&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return _NextControl&lt;br&gt;
&amp;nbsp;&amp;nbsp;End Get&lt;br&gt;
&amp;nbsp;&amp;nbsp;Set(ByVal value As Control)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_NextControl = value&lt;br&gt;
&amp;nbsp;&amp;nbsp;End Set&lt;br&gt;
End Property[/codesnippet]&lt;br&gt;
&lt;br&gt;
Now you can use Me.NextControl.Focus() to set focus on that control.  Have fun playing with this. :D</description><pubDate>Wed, 02 Jun 2010 21:10:45 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>