Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

randomise TAB order VB.NET 2003/2010

Posted on 2011-03-11
12
Medium Priority
?
423 Views
Last Modified: 2012-05-11
Hi Experts,

I wish to find a solution to randomly change tab order on form load. (WinForm)... I have searched the net but only found issues regarding the problems within 2003 edition...

I have no code examples - sorry :(

Thanks,
Roberto
0
Comment
Question by:RobertoFreemano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111492
Is this for VB or Delphi?
0
 
LVL 7

Expert Comment

by:foobarr
ID: 35112091
on page load you could go

dim ctrl as control
dim rando as new random()

for each ctrl in frmName.controls

ctrl.TabIndex = rando.Next()


next
0
 

Author Comment

by:RobertoFreemano
ID: 35112157
Hi kaufmed,

VB.NET 2003/2010

Thanks,
Roberto
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:RobertoFreemano
ID: 35112190
Hi foobarr,

I get the following error:

An unhandled exception of type 'System.NullReferenceException' occurred in certstar.exe
Additional information: Object reference not set to an instance of an object.


on  ctrl.TabIndex = rando.Next()
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35112205
Then foobarr's example should suit you. The only thing you may have issue with is controls which contain other controls (GroupBox, Panel, etc.). In that case, you may consider having a recursive function to grab all controls. You could also use a Linq-based approach to grabbing all controls.
0
 

Author Comment

by:RobertoFreemano
ID: 35112225
Thanks kaufmed,

I'm not sure how to proceed. :(

Roberto
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 420 total points
ID: 35112231
You could do:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim tabs As New ArrayList
        For Each tp As TabPage In TabControl1.TabPages
            tabs.Add(tp)
        Next
        TabControl1.TabPages.Clear()

        Dim i As Integer
        Dim R As New Random
        While tabs.Count > 0
            i = R.Next(0, tabs.Count)
            TabControl1.TabPages.Add(tabs(i))
            tabs.RemoveAt(i)
        End While
    End Sub

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 80 total points
ID: 35112340
Something like this:
Public Class Form1
    Private rand As New Random(DateTime.Now.TimeOfDay.Milliseconds)

    Public Sub RecurseChildren(ByRef ctl As Control)
        For Each child As Control In ctl.Controls
            RecurseChildren(child)
        Next

        ctl.TabIndex = rand.Next(1, 1000)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RecurseChildren(Me)
    End Sub
End Class

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35112383
I see I misread the question!  =)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35112415
Heheh. Don't worry, we won't hold it against you  ; )
0
 

Author Closing Comment

by:RobertoFreemano
ID: 35112543
Thanks Idle_MInd, you solution worked.

Kaufmed, I couldn't get your solution to work, but thanks anyway.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35115596
I guess you didn't misread after all Idle....   everyone else did!

Good show old bean   :  )
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question