2

I have a label that is bound to a BindingSource. The label text populates correctly, but I cannot retrieve that information. In other words, I can SEE the correct text, but I cannot use it in my code as follows:

Public Sub LoadImage(ByVal caseNum As String, ByVal commnum As String)
    If Me.SpGetLOMCDocumentPathTableAdapter.GetData(caseNum, commnum).Count > 0 Then
        Try
            Me.SpGetLOMCDocumentPathTableAdapter.Fill(Me.DevGISDataSet.spGetLOMCDocumentPath, caseNum, commnum)

            Dim docPath As New BindingSource
            docPath = Me.SpGetLOMCDocumentPathBindingSource

            Me.bnTIF.BindingSource = docPath

            Me.lblDocPath.DataBindings.Add(New System.Windows.Forms.Binding("Text", docPath, "DocPath", True))

            Dim currentPath As String = Nothing

            currentPath = Me.lblDocPath.Text
            MessageBox.Show(Me.lblDocPath.Text)

            Me.Show()
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message.ToString)
        End Try
    Else
        MessageBox.Show("Image not available. Please check FEMA and CAMSIS.")
        Exit Sub
    End If
End Sub

No error is thrown, the messagebox is blank. This method works with textboxes on other forms.

Using binding handler

Public Sub LoadImage(ByVal caseNum As String, ByVal commnum As String)
    If Me.SpGetLOMCDocumentPathTableAdapter.GetData(caseNum, commnum).Count > 0 Then
        Try
            Me.SpGetLOMCDocumentPathTableAdapter.Fill(Me.DevGISDataSet.spGetLOMCDocumentPath, caseNum, commnum)

            Dim docPath As New BindingSource
            docPath = Me.SpGetLOMCDocumentPathBindingSource

            Me.bnTIF.BindingSource = docPath
            'Me.dgDocPath.DataSource = docPath

            AddHandler docPath.BindingComplete, AddressOf Me.HandleBindingCompleted

            Me.lblDocPath.DataBindings.Add(New System.Windows.Forms.Binding("Text", docPath, "DocPath", True))
            Me.txtDocPath.DataBindings.Add(New System.Windows.Forms.Binding("Text", docPath, "DocPath", True))

            Me.Show()
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message.ToString)
        End Try
    Else
        MessageBox.Show("Image not available. Please check FEMA and CAMSIS.")
        Exit Sub
    End If
End Sub

Private Sub HandleBindingCompleted(ByVal sender As Object, ByVal e As BindingCompleteEventArgs)
    MessageBox.Show("Test")
    If (Not e.Exception Is Nothing) Then
        Debug.WriteLine(e.ErrorText)
        MessageBox.Show(e.ErrorText)
    Else
        MessageBox.Show("No error")
    End If
End Sub

Even the "Test" message box fails to appear.

Calling this method

Public Sub LoadLOMCImage(ByVal casenum As String, ByVal commnum As String)
    Try
        DisposeLOMCForm()

        Dim LOMCtif As New frmLOMCTiff
        LOMCtif.LoadImage(casenum, commnum)
    Catch ex As Exception
        MessageBox.Show("Error finding LOMC image: " & ex.Message.ToString)
    End Try
End Sub

I call the LoadImage Sub from a separate form. Again, the data passed correctly, I can read the data correctly using the GetData method of the TableAdapter. I can set the BindingSource to a DataGridView, but I have the same problem: I can see the rows of data, but cannot access the row with an index of 0 (basic exception, index out of range, etc).

Using suggested code:

Public Sub LoadImage(ByVal caseNum As String, ByVal commnum As String)
    If Me.SpGetLOMCDocumentPathTableAdapter.GetData(caseNum, commnum).Count > 0 Then
        Try
            Me.SpGetLOMCDocumentPathTableAdapter.Fill(Me.DevGISDataSet.spGetLOMCDocumentPath, caseNum, commnum)

            Dim docPath As New BindingSource
            docPath = Me.SpGetLOMCDocumentPathBindingSource

            Me.bnTIF.BindingSource = docPath

            Dim b1 = New System.Windows.Forms.Binding("Text", docPath, "DocPath", True)

            AddHandler b1.BindingComplete, AddressOf Me.HandleBindingCompleted

            Me.lblDocPath.DataBindings.Add(b1)

            Dim currentPath As String = Nothing

            currentPath = Me.lblDocPath.Text
            MessageBox.Show(b1.Control.Text)

            If Not String.IsNullOrEmpty(currentPath) Then
                If currentPath.Contains(".TIF") Then
                    LoadTIF()
                End If

                If currentPath.Contains(".pdf") Then
                    LoadPDF()
                End If
            End If

            'FindImage()

            Me.Show()
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message.ToString)
        End Try
    Else
        MessageBox.Show("Image not available. Please check FEMA and CAMSIS.")
        Exit Sub
    End If
End Sub

Private Sub HandleBindingCompleted(ByVal sender As Object, ByVal e As BindingCompleteEventArgs)
    MessageBox.Show(String.Format("{0}: {1}", e.Binding.BindingMemberInfo.BindingMember, e.Binding.Control.Text))
    If (Not e.Exception Is Nothing) Then
        Debug.WriteLine(e.ErrorText)
    End If
End Sub

Again, the binding is successful, but I cannot access the label text.

alybaba726
  • 390
  • 4
  • 14

0 Answers0