Setting focus to a particular control based on TabOrder on TabOrderController


Author
Message
Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K 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
Reply
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K 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
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