Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to dynamically create a form with the code below. The form is created perfectly. However, I need to get xxx to run as the dynamic form closes.

 

I added a handler, but it gives me an error ("does not have the same signature as the delagate 'Delegate Sub CanceleventHandler'"). I do not see what is wrong.

 

Can anyone help?

 

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
       Dim f As New Form
       Dim ADO As New ADONET
       Dim SQL As String = "SELECT * FROM MiscData"
       Dim Cmd As SqlCommand = ADO.GetCmd(SQL, ADO.SetCnn(ADO.CnnStrBdgTot))
       Dim DS As DataSet
       Dim DA As SqlDataAdapter = ADO.GetDA(Cmd, DS)
       Dim DR As SqlDataReader = Cmd.ExecuteReader

       Dim FldCnt As Int16 = DS.Tables(0).Columns.Count
       Dim X As Int16
       Dim txtBox As TextBox

       Dim CtrlTop As Int16 = 10
       DR.Read()
       For X = 1 To FldCnt - 1
           txtBox = New TextBox
           With txtBox
               .Name = DS.Tables(0).Columns(X).ColumnName
               .Top = CtrlTop
               .Left = 100
               .Text = DR(X)
           End With
           Dim lbl As New Label
           With lbl
               .Top = CtrlTop
               .Name = "lbl" & txtBox.Name
               .Text = txtBox.Name
               CtrlTop += .Height
           End With

           f.Controls.Add(lbl)
           f.Controls.Add(txtBox)
       Next
       AddHandler f.Closing, AddressOf xxx

       f.Show()
   End Sub

   Private Sub xxx(ByVal sender As System.Object, ByVal e As System.EventArgs)
       Dim t As System.Windows.Forms.Control
       Dim f As Form = Me
       Dim x As String
       Dim SQL As String = "UPDATE MiscData SET "
       For Each t In f.Controls
           If TypeOf t Is TextBox Then
               SQL = SQL & t.Name & "='" & t.Text & "', "
           End If
       Next t
       SQL = Mid(SQL, 1, Len(SQL) - 2)
       Dim ado As New ADONET
       ado.ActionSQL(SQL, ado.SetCnn(ado.CnnStrBdgTot))
   End Sub

Go Beavs!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...