ArgumentException

N

NetRacer

hi all,

i have a form with a tabcontrol with 4 pages. on the first page are many
controls bound to a database. now i bound the controls of page two (two
multiline textboxes, four SelectedValues) to the db. the program compiles
without an error and runs fine, until i click on tabpage 2. then the program
throws the following exception:

System.ArgumentException: Der Objekttyp kann nicht zum Zieltyp konvertiert
werden. (english: Object type cannot be converted to target type)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.TabPage.set_Visible(Boolean value)
at System.Windows.Forms.TabControl.UpdateTabSelection(Boolean uiselected)
at System.Windows.Forms.TabControl.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.TabControl.WmSelChange(Message& m)
at System.Windows.Forms.TabControl.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,
Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam,
IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd,
Message& m)
at System.Windows.Forms.Control.WmNotify(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TabControl.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)


there is no line number of my code in the stacktrace, so i don't know where
to look. can anyone help me?

thx for any help
netracer
 
C

Cor Ligthert

NetRacer,

Your question has a standard answer that is long time not given.

Put in the top of your program file.
Option Strict On

Probably you will than see the error.
And feel than free to ask when you don't know how to solve that.
(It needs than probably converting or casting)

I hope this helps,

Cor
 
A

Armin Zingler

Cor Ligthert said:
Your question has a standard answer that is long time not given.

Put in the top of your program file.
Option Strict On


In which file of the source files for System.Windows.Forms.dll?

;-)

Armin
 
N

NetRacer

i tried.
after the correction (insert of CType(x,y)) of a lot of value assignments i
recompiled my project and the effect is the same.
i tried the option strict in every code file the code of this form goes
through.

the error message is still the same, without any hint, where to search
for...
 
N

NetRacer

tabPage2 does nothing. there is no event handled.
i bound the error to three controls on it now. if i comment out the
DataBindings of these, it works.

each of these controls is an inherited GroupBox with additional property
"Value", nothing else changed. the Value is set by RadioButtons within the
GroupBox and vice versa sets the RadioButtons.

----------
the GroupBox Class:


Public Class myGroupBox
Inherits GroupBox

Private m_value As Object
Private m_setvalue As Boolean = False

Public Event ValueChanged(ByVal sender As Object, ByVal e As EventArgs)

<Description("The value of the selected RadioButton"), _
Browsable(False), Bindable(True)> _
Public Property Value() As Object
Get
Return m_value
End Get
Set(ByVal Value As Object)
m_value = Value
RaiseEvent ValueChanged(Me, New EventArgs)
End Set
End Property

Public Sub SetValue(ByVal val As Object)
m_value = val
End Sub

End Class

---------
in the Form:


Private Sub grpFlag_KP_ValueChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles grpFlag_KP.ValueChanged
Select Case grpFlag_KP.Value
Case 2 : rdoFlag_Kostenteilung.Checked = True
Case 1 : rdoFlag_kostenpflichtig.Checked = True
Case 0 : rdoFlag_kostenlos.Checked = True
End Select
End Sub


Private Sub rdoFlag_Kostenteilung_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
rdoFlag_Kostenteilung.CheckedChanged
If CType(sender, RadioButton).Checked Then grpFlag_KP.SetValue(2)
End Sub

Private Sub rdoFlag_kostenpflichtig_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
rdoFlag_kostenpflichtig.CheckedChanged
If CType(sender, RadioButton).Checked Then grpFlag_KP.SetValue(1)
End Sub

Private Sub rdoFlag_kostenlos_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdoFlag_kostenlos.CheckedChanged
If CType(sender, RadioButton).Checked Then grpFlag_KP.SetValue(0)
End Sub
 
C

Cor Ligthert

NetRacer,
tabPage2 does nothing. there is no event handled.
i bound the error to three controls on it now. if i comment out the
DataBindings of these, it works.
Than it is probably in that part, however in my opinion did you not show
that.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top