0

Hi, i am having problem with my vb project to clear all item in my form. Below is the code that i am using :

Dim ctrl, obj as control

For Each ctrl in Me.controls
  If typeof ctrl is GroupBox then
     For Each obj In ctrl.Controls
       If typeof obj is TextBox or typeof is ComboBox or typeof is ListBox then
         obj.text =""
  End if
Next
  Elseif typeof ctrl is TextBox then 
     ctrl.text = ""
  End if
Next

The error is :

InvalidCastException was unhandled
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional Information : Conversion from string "" to type 'Double' is not valid.

Please Enlighten me. I really do not understand it.

4
Contributors
4
Replies
29
Views
3 Years
Discussion Span
Last Post by kb.net
0

did you try the .Clear() method? I'm not sure because I'm not testing this at them moment but perhaps

obj.Clear()
0

please try
---> If typeof obj is TextBox or typeof is ComboBox or typeof is ListBox then
case 1.change to
---> If (typeof obj is TextBox) or (typeof obj is ComboBox) or (typeof obj is ListBox) then
case 2.change to
If typeof obj is TextBox then
........
end if
if typeof obj is ComboBox then
........
end if

and so on

0

I think Pollatep is correct, your if statement is wrong. you have to add the object with each condition:

If typeof obj is TextBox or typeof obj is ComboBox or typeof obj is ListBox then
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.