我有两种形式。我已经在datagridview中以一种形式显示了一些值,这些值连接到ms访问数据库。当我从第二个表单中的第一个数据视图中单击一行时,屏幕上会出现一个行,并在文本框中显示数据。我试过以下代码但没有成功。有人可以帮忙吗感谢
Public Class Main_Frm
Private Sub TBL_TEAMSBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBL_TEAMSBindingNavigatorSaveItem.Click
Me.Validate()
Me.TBL_TEAMSBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.FootBallDataSet)
End Sub
Private Sub Main_Frm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'FootBallDataSet.TBL_TEAMS' table. You can move, or remove it, as needed.
Me.TBL_TEAMSTableAdapter.Fill(Me.FootBallDataSet.TBL_TEAMS)
End Sub
Private Sub TBL_TEAMSDataGridView_Click(sender As Object, e As EventArgs) Handles TBL_TEAMSDataGridView.Click
If TBL_TEAMSDataGridView.SelectedRows.Count Then
Dim Schedule_Form As New Schedule_Frm
Schedule_Form.SelectRows = TBL_TEAMSDataGridView.SelectedRows
Schedule_Form.ShowDialog()
End If
End Sub
结束班
答案 0 :(得分:0)
我不知道Schedule_Form中的“SelectRows”是什么,但是,我会在Schedule_Form中执行以下操作:
Public RID as int32
Public Sub LoadMyRecordFromDataSource()
' your data loading function for 1 record here, use RID as a key
End Sub
然后,在您的主窗体中(提供,您可以在文本框中一次只编辑一行 - 在这种情况下您的代码将失败):
Private Sub TBL_TEAMSDataGridView_Click(sender As Object, e As EventArgs) Handles TBL_TEAMSDataGridView.Click
If TBL_TEAMSDataGridView.SelectedRows.Count Then
Dim Schedule_Form As New Schedule_Frm
Schedule_Form.RID = TBL_TEAMSDataGridView.SelectedRows(0).Cells("ID").value ' get your ID
Schedule_Form.LoadMyRecordFromDataSource() ' load your selected record
Schedule_Form.ShowDialog()
End If
End Sub