これは、フォームの詳細を表示するために、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
どなたか情報頂ければと思います。ありがとうございました!:)