Possible use of multiple Tab Indexes - Investigation Script

I participated in a question which I interpreted that the cause of the problem was that the user could have the same tab index assigned to multiple controls.  I decided to create a small recursive script to investigate whether or not this was true.  Please find the example script below, I hope it is of some use to anyone.  Nothing special but I thought it could reduce time if a form had a considerable amount of controls.

TabIndexInvestigation

The Code

        private void Form_Load(object sender, EventArgs e)
        {
            RecursiveCheck(this);
            StringBuilder sb1 = new StringBuilder();
            foreach (KeyValuePair<int, List<string>> pair in aggregation)
            {
                sb1.AppendLine(String.Format("Tab Index : {0} Is Assigned To Controls : {1}",
                    pair.Key, String.Join(",", pair.Value.ToArray())));
            }
            MessageBox.Show(sb1.ToString());
        }

        public static Dictionary<int, List<string>> aggregation;

        private void RecursiveCheck(Control c)
        {
            foreach (Control control in c.Controls)
            {
                if (aggregation == null)
                    aggregation = new Dictionary<int, List<string>>();

                if (aggregation.ContainsKey(control.TabIndex))
                    aggregation[control.TabIndex].Add(control.Name);
                else
                    aggregation.Add(control.TabIndex, new List<string>(new string[] { control.Name }));
                RecursiveCheck(control);
            }
        }
Published Monday, March 10, 2008 1:22 PM by REA_ANDREW

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)