第一次发帖,是vb.net数据库的初学者。
我在form1上有一个datagridview,它通过数据源填充。 (从文件访问数据库)。在form1上我有datagridview来显示我的所有“项目和细节。我可以双击单元格或单击按钮转到编辑项目表单。在编辑项目表单上,我已经放置了预定义的详细信息datasource。(文本框,复选框等)
现在我的问题是,当我转到“编辑项目”表单时,它不会浏览所选行的详细信息,而是默认的第一行详细信息。
在表单加载时,适配器会像这样填充。
Me.ProjectsTableAdapter.Fill(Me.ProjectsXDataSet.Projects)
当我转到编辑表格
Public Sub Editproject()
'Disable form 1 to lock interface while editing a project
'
Me.Enabled = False
Form2.Show()
End Sub
Public Sub CellDoubleClick()
Form2.TextBox1.Text = ""
Form2.TextBox2.Text = ""
Form2.DataGridView1.DataSource = Nothing
Dim filenme As String = Form2.ProjectTextBox.Text & ".txt"
If My.Computer.FileSystem.FileExists(filenme) = True Then
Form2.TextBox2.Text = My.Computer.FileSystem.ReadAllText(Form2.ProjectTextBox.Text & ".txt")
Dim pathfolder As String = Form2.TextBox2.Text
Dim stringpath As String = pathfolder & "\" '
Form2.DataGridView1.DataSource = Fileinfo_To_DataTable(pathfolder)
Else
' MsgBox("Please add a workfolder")
End If
Try
Dim project As String = Form2.ProjectTextBox.Text
Dim filenme2 As String = project & " notes.txt"
Form2.TextBox1.Text = My.Computer.FileSystem.ReadAllText(filenme2)
Catch ex As Exception
End Try
End Sub
我尝试过更新tableadaptor,但我无法解决任何问题。
启动代码添加:
Private Sub EditProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditProjectToolStripMenuItem.Click
Editproject()
CellDoubleClick()
End Sub
OR
Private Sub DataGridView1_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Editproject()
CellDoubleClick()
End Sub
参见图片....我在datagridvew中双击所选行,这将打开编辑表单(form2)。但是使用链接的文本框,它会显示第1行(0)的值 enter image description here