tags:

views:

184

answers:

0

sorry about not making myself clear enough and not putting enough effort (wont happen again :)). i'm building a form App where users have to fill out the form. i have a TabControl with 3 TabItem one of the TabItem has TextBoxes the second has TextBoxes and RadioButton and third has only CheckBoxes. i have written a code to dictect error by on clicking submit using ValidationRule/ValidationResult and and using GroupBinding (got it from msdn samples). now the problem am having is code to search through the tabs, compare the controls (e.g. controlA,controlB) to know wich one comes before the other and return the tabindex. one of the use i want with this is letting the user jump to the uncompleted TextBox,RadioButton or CheckBoxes in order like starting from the first Tabitem in the TabControl

with this code i could work the tree to locate the controls(code from Philipp Sumi blog but i modified it a little)

        private void Button_Click(
            object sender, 
            RoutedEventArgs e)
    {
        IEnumerator enumerator = FindLogicalChildren(_parentStackPanel).GetEnumerator();

         while (enumerator.MoveNext())
           MessageBox.Show(enumerator.Current.ToString());
    }


    private IEnumerable FindLogicalChildren(
        DependencyObject depObj)
    {
        if (depObj != null)
        {
            foreach (object childObj in LogicalTreeHelper.GetChildren(depObj))
            {
                DependencyObject child = childObj as DependencyObject;
                if (child != null && child is Control)
                {
                    yield return (Control)child;
                }
                foreach (Control childOfChild in FindLogicalChildren(child))
                {
                    yield return childOfChild;
                }
            }
        }
    }

but i dodnt know how continue to get the tabindex of each control in order form as i work down the tree. can any one please help me on this? Thanks

im using this method:

        private int Compare(
        Control controlA,
        Control controlB)
    {
        DependencyObject commonAncestor = controlA.FindCommonVisualAncestor(controlB);

        for (int index = 0; index < VisualTreeHelper.GetChildrenCount(commonAncestor); index++)
        {
            Visual childVisual = (Visual)VisualTreeHelper.GetChild(commonAncestor, index);
            Control control = (Control)childVisual;
            control.TabIndex = index;
        }

        return controlA.TabIndex.CompareTo(controlB.TabIndex);
    }

that returns 1,-1 or 0 to compare two controls to find out which one comes before the other. the question is, can anyone tell me a better way of doing this.