SonicBoomAu Posted August 16, 2006 Posted August 16, 2006 Hi All, Is it possible to do something like this?? I get a blue line under "ErrorProvider1.SetError(Txt.Name, " and "ErrorProvider1.SetError(Cbo.Name" The mouse over states "Value of type 'String' cannot be converted to 'System.Windows.Forms.Control" ' Loop through each control on the StaticGroupBox ' If control.text is blank then display error icon on that feild Dim Ctrl As Control Dim Txt As TextBox Dim Cbo As ComboBox For Each Ctrl In Me.gbxSecurityInfo.Controls If TypeOf (Ctrl) Is TextBox Then Txt = CType(Ctrl, TextBox) If Txt.Text = vbNullString Then ' Display Error Icon next to control ErrorProvider1.SetError(Txt.Name, "This feild can not be left blank") Else ErrorProvider1.SetError(Txt.Name, "") End If 'Txt.Text = vbNullString Then End If ' TypeOf (CTRL) is TextBox If TypeOf (Ctrl) Is ComboBox Then Cbo = CType(Ctrl, ComboBox) If Cbo.Text = vbNullString Then ' Display Error Icon next to control ErrorProvider1.SetError(Cbo.Name, "This feild can not be left blank") Else ErrorProvider1.SetError(Cbo.Name, "") End If 'Cbo.Text = vbNullString Then End If ' TypeOf (Ctrl) Is ComboBox Then Next BTW i'm using VB .Net 2003 Thanks you for your time and help in advance. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
*Experts* DiverDan Posted August 16, 2006 *Experts* Posted August 16, 2006 Hi SonicBoomAu, The error is correct as the ErrorProvider accesses the control, not its string name. Try this instead: Dim Ctrl As Control Dim txtBox As TextBox Dim combo As ComboBox For Each Ctrl In Me.gbxSecurityInfo.Controls If TypeOf Ctrl Is TextBox Then txtBox = CType(Ctrl, TextBox) If txtBox.Text = String.Empty Then ' Display Error Icon next to control ErrorProvider1.SetError(txtBox, "This field can not be left blank") Else ErrorProvider1.SetError(txtBox, "") End If 'Txt.Text = String.Empty Then End If ' TypeOf CTRL is TextBox If TypeOf Ctrl Is ComboBox Then combo = CType(Ctrl, ComboBox) If combo.Text = String.Empty Then ' Display Error Icon next to control ErrorProvider1.SetError(combo, "This field can not be left blank") Else ErrorProvider1.SetError(combo, "") End If 'Cbo.Text = String.Empty Then End If ' TypeOf Ctrl Is ComboBox Then Next Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
SonicBoomAu Posted August 16, 2006 Author Posted August 16, 2006 Thanks for the prompt reply DiverDan. That fixed that problem, but identified another one. I wont to loop through all the controls on the groupbox, but am only getting the controls on the form. What am i donig wrong. Thanks in advance Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
*Experts* DiverDan Posted August 16, 2006 *Experts* Posted August 16, 2006 Is gbxSecurityInfo the groupbox that has the controls that you want to loop through? If so then the code is correct. If not then you'll need to change gbxSecurityInfo to the correct groupbox. Another thought is; are you sure that the controls are part of gbxSecurityInfo's controls and not the form's? You might want to check that. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
SonicBoomAu Posted August 16, 2006 Author Posted August 16, 2006 Thanks DiverDan. Shoot me now. Wrong name. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.