On the tab control, I do validation for each control on submit. One or more controls could have error. I want some way to highlight the tab(s) which contains the control with error.
Surely people have encountered this scenario and already have an elegant solution.
Hello,
Off the top of my head, it seems the most logical solution would be walk up the Parent chain of any control failing validation looking for the owning UltraTabPageControl. Once it finds the UltraTabPageControl, set the Tab.Appearance.Image property to indicate there is an error.
Code similar to the following will keep track of the tabs with controls failing validation, and set the image at the end:
List<UltraTab> errorTabList = new List<UltraTab>();
foreach (Control controlBeingValidated in new Control[] { this.textBox1, this.textBox2, this.textBox3, this.textBox4 })
{
if (PerformValidationOnControl(controlBeingValidated) == false)
// Validation Failed
Control parentControl = controlBeingValidated.Parent;
UltraTabPageControl page = null;
// Find the containing Tab
while (parentControl != null)
page = parentControl as UltraTabPageControl;
if (page != null)
break;
parentControl = parentControl.Parent;
}
// Add the Tab to the list of Tabs with errors
if (page != null &&
errorTabList.Contains(page.Tab) == false)
errorTabList.Add(page.Tab);
// Once all controls have been validated.
// Loop through all tabs and either set or reset the image
// based on the tab's existance in the error list.
foreach (UltraTab tab in this.ultraTabControl1.Tabs)
if (errorTabList.Contains(tab))
tab.Appearance.ImageHAlign = Infragistics.Win.HAlign.Right;
tab.Appearance.Image = SystemIcons.Error.ToBitmap();
else
tab.Appearance.ResetImage();
Let me know if you have additional questions regarding this.
Thanks,
Chris