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 に答える