0

这是我在 Families 表的数据网格视图的“双击”事件中的代码 - 为了在表单上显示详细信息:

“showrow()”是根据数据库索引填写表单的子程序。dsFamilies- DataSet, daFamilies-DataAdapter, counter - 一个全局变量

Private Sub dtgFamilies_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgFamilies.CellContentDoubleClick

    counter = e.RowIndex
    ShowRow() // the problem: "There is no row at position 0" while my Data Base is //abound with data.
    Dim i As Integer = 0
    For i = 0 To (dsFamilies.Tables.Item("tblFamilies").Rows.Count - 1)
        If (dsFamilies.Tables("tblFamilies").Rows(i).Item("familyId") = dtgFamilies.Rows(counter).Cells(0).Value) Then
            counter = i
            ShowRow()

        End If
    Next
    tbControlFml.SelectTab(1)
End Sub



Sub ShowRow()

    txtId.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyId")
    txtFirstName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyFirstName")
    txtLastName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyLastName")
    txtStreet.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAdress")
    comboCity.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCity")
    txtHouseNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyHouseNum")
    txtPhoneNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyTeleNum")
    txtCellNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCellNum")
    txtEmail.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyEmail")
    txtNumPeoFamily.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPeopleNum")
    chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyChildren")
    chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyBaby")
    comboPckType.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPackgId")
    chkAvailable = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAvailable")
    comboEntityApp = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAppEntityId")
    dtpJoin.Value = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyJoinDate")
    txtRemark.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyRemark")

    Dim subPhone As String = txtPhoneNum.Text.Substring(0, 2)
    Dim subCellPhone As String = txtCellNum.Text.Substring(0, 3)
    If ((subPhone = "077") Or (subPhone = "02") Or (subPhone = "03") Or (subPhone = "04") Or (subPhone = "08") Or (subPhone = "09")) Then
        comboPhoneIni.Text = subPhone
        txtPhoneNum.Text = txtPhoneNum.Text.Substring(2, 7)
    End If
    If ((subCellPhone = "050") Or (subCellPhone = "052") Or (subCellPhone = "054") Or (subCellPhone = "057")) Then
        comboCellIni.Text = subCellPhone
        txtCellNum.Text = txtCellNum.Text.Substring(3, 7)
    End If

End Sub

我想得到你能提供的任何信息。谢谢!:)

4

1 回答 1

0

这意味着这些使用不包括 DGV 行的数据库结果的计数值:

    Private Sub dtgFamilies_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgFamilies.CellContentDoubleClick 
        For i As Int16 = 0 To dtgFamilies.Rows.Count - 1 
            For e As Int16 = 0 To (dsFamilies.Tables.Item("tblFamilies").Rows.Count - 1) 
                If (dsFamilies.Tables("tblFamilies").Rows(e).Item("familyId") = dtgFamilies.Item(0, i).Value) Then 
                   counter = i 
                   Call ShowRow() 
                End If 
            Next e
        Next i
        tbControlFml.SelectTab(1) 
    End Sub 

    Sub ShowRow() 

        txtId.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyId") 
        txtFirstName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyFirstName") 
        txtLastName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyLastName") 
        txtStreet.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAdress") 
        comboCity.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCity") 
        txtHouseNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyHouseNum") 
        txtPhoneNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyTeleNum") 
        txtCellNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCellNum") 
        txtEmail.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyEmail") 
        txtNumPeoFamily.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPeopleNum") 
        chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyChildren") 
        chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyBaby") 
        comboPckType.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPackgId") 
        chkAvailable = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAvailable") 
        comboEntityApp = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAppEntityId") 
        dtpJoin.Value = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyJoinDate") 
        txtRemark.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyRemark") 

        Dim subPhone As String = txtPhoneNum.Text.Substring(0, 2) 
        Dim subCellPhone As String = txtCellNum.Text.Substring(0, 3) 
        If ((subPhone = "077") Or (subPhone = "02") Or (subPhone = "03") Or (subPhone = "04") Or (subPhone = "08") Or (subPhone = "09")) Then 
            comboPhoneIni.Text = subPhone 
            txtPhoneNum.Text = txtPhoneNum.Text.Substring(2, 7) 
        End If 
        If ((subCellPhone = "050") Or (subCellPhone = "052") Or (subCellPhone = "054") Or (subCellPhone = "057")) Then 
            comboCellIni.Text = subCellPhone 
            txtCellNum.Text = txtCellNum.Text.Substring(3, 7) 
        End If 

    End Sub 

它将逐一比较。

于 2012-06-12T22:29:13.077 回答