locked
System.InvalidCastException RRS feed

  • Question

  • I am trying to apply settings to controls.  The first code example works fine, but the second does not and it produces an error.

    Public Sub ClearBindingsLoop(ByVal pan As Panel) ' Clear bindings on the panel's controls
            Dim ctl As Control
    
            ' Examine every control.
            For Each ctl In pan.Controls
                On Error Resume Next
                ctl.DataBindings.Clear()
                On Error GoTo 0
            Next ctl
        End Sub
     Public Sub SetEditDateControl(ByVal pan As Panel) ' Clear bindings on the panel's controls
    
            Dim ctl As DateEdit
    
            For Each ctl In pan.Controls
    
                On Error Resume Next
                ctl.Properties.Mask.UseMaskAsDisplayFormat = True
                ctl.Properties.Mask.EditMask = "MM/dd/yyyy"
                ctl.Properties.DisplayFormat.FormatString = "MM/dd/yyyy"
                On Error GoTo 0
    
            Next ctl
    
        End Sub
    

    System.InvalidCastException
      HResult=0x80004002
      Message=Unable to cast object of type 'System.Windows.Forms.Label' to type 'DevExpress.XtraEditors.DateEdit'.
      Source=FosterTrak
      StackTrace:
       at FosterTrak.basMain.SetEditDateControl(Panel pan) in C:\VS2017\Projects\FosterTrak\Code\Modules\basMain.vb:line 338
       at FosterTrak.CLMain.CLMain_Load(Object sender, EventArgs e) in C:\VS2017\Projects\FosterTrak\Code\Forms\CLMain.vb:line 102
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Any help will be appreciated.


    ISV using VB.net and SQL Server

    Wednesday, June 24, 2020 9:45 PM

Answers

  • 'DevExpress.XtraEditors.DateEdit'.

    Hi

    Third party controls are not supported here, but try the DevExpress site.


    Regards Les, Livingston, Scotland

    • Marked as answer by Jeff07 Wednesday, June 24, 2020 9:57 PM
    Wednesday, June 24, 2020 9:55 PM