Page 1 of 1

accessing custom controls on a form

PostPosted: Wed Nov 11, 2015 1:57 pm
by indikad
I have placed a custom control on Sales order form using some of Scotts sampel code.
I howver have a bit of truble accessing it from another event.
on the SalesOrderReadEnd sub - when I invoke the line DirectCast - I get the error "Object Reference Not set to an instance... "

I want to change the lable text and color

the bit fo code that fails is
Code: Select all
Dim lbl As  Infragistics.Win.Misc.UltraLabel  = DirectCast(_SalesOrderForm.GenericObjectCollection.Item("lblAlert").Object ,  Infragistics.Win.Misc.UltraLabel)


the entire code is below.

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      
      If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.SalesOrderEntryForm Then
         Dim SalesOrdForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)         
         _SalesOrderForm = SalesOrdForm
         AddHandler SalesOrdForm.SalesOrder.ReadEnd  , AddressOf SalesOrderReadEnd
         SalesOrderFormLoad(SalesOrdForm, New System.EventArgs)   
      End If
         
    End Sub
   Private Sub SalesOrderFormLoad(ByRef sender As Object , e As System.EventArgs )
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm Then
         Dim oSalesOrder As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
         
         'Create a lable control and set it up
         Dim lblAlert As New Infragistics.Win.Misc.UltraLabel
         lblAlert.Name = "lblAlert"
         lblAlert.Text = "*** No Alerts ***"
         lblAlert.Width = 130
         lblAlert.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle
         lblAlert.ForeColor = System.Drawing.Color.Black ' vbBack
         
         'Add it to the form
         oSalesOrder.Controls.Add(lblAlert) 'A neat way to figure out the parent control (HeaderUltraExpandableGroupBoxPanel) is to open the purhcase order form, then go into permission mode.  Clicking on the form then reveals the underlying control names on the Set Permissions dialog.
         lblAlert.Location = New System.Drawing.Point (60 , 50 )
      
         
      End If
   End Sub
   Sub SalesOrderReadEnd (ByVal sender As Object ,e As System.EventArgs )
      Try         
                  
         Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast( sender , JiwaSales.SalesOrder.SalesOrder)

         msgbox ( " sales order  read completd  - ReadEnd ")
         
         msgbox (" before direct cast ")
a
         Dim lbl As  Infragistics.Win.Misc.UltraLabel  = DirectCast(_SalesOrderForm.GenericObjectCollection.Item("lblAlert").Object ,  Infragistics.Win.Misc.UltraLabel)
         msgbox (" before lable text ")
         lbl.Text = "new alert now"
         msgbox (" before color ")
         lbl.BackColor = System.Drawing.Color.Red
         '_SalesOrderForm.GenericObjectCollection.("lblAlert").BackColor = System.Drawing.Color.Red
      Catch ex As Exception
         MessageBox.Show( ex.Message)
      End Try      
   End Sub

Re: accessing custom controls on a form  Topic is solved

PostPosted: Fri Nov 13, 2015 10:19 am
by Scott.Pearce
Code: Select all
Dim lbl As  Infragistics.Win.Misc.UltraLabel  = DirectCast(_SalesOrderForm.GenericObjectCollection.Item("lblAlert").Object ,  Infragistics.Win.Misc.UltraLabel)



Dear me. Why are you looking in the GenericObjectCollection for your label? You never placed it in there! You should be looking in the forms' controls collection thus:

Code: Select all
Dim lbl As  Infragistics.Win.Misc.UltraLabel  = DirectCast(_SalesOrderForm.Controls("lblAlert"),  Infragistics.Win.Misc.UltraLabel)