我在vb2013中遇到了以下数据库和datagrid更新试用版的一些问题。 我有一个数据网格和一个"创建新的配置文件" Form1(uebersicht)上的按钮(btnnewprofile),按钮打开Form2(neuesprofil)作为ShowDialog()。
如何在Form1的数据网格中显示Form2的输入?
这里是Form1的代码
Public Class uebersicht
Private Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
' Me.Validate()
' Me.TableBindingSource.EndEdit()
' Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
End Sub
Private Sub uebersicht_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: Diese Codezeile lädt Daten in die Tabelle "Database1DataSet.Table". Sie können sie bei Bedarf verschieben oder entfernen.
' Me.TableTableAdapter.Fill(Me.Database1DataSet.Table)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnnewprofile.Click
neuesprofil.ShowDialog()
End Sub
Public Sub TableDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles TableDataGridViewuebersicht.CellContentClick
End Sub
结束班
表格2的代码
Public Class neuesprofil
Public Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
End Sub
' Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: Diese Codezeile lädt Daten in die Tabelle "Database1DataSet.Table". Sie können sie bei Bedarf verschieben oder entfernen.
' Me.TableTableAdapter.Fill(Me.Database1DataSet.Table)
' End Sub
Public Sub btnsvprfl_Click(sender As Object, e As EventArgs) Handles btnsvprfl.Click
uebersicht.TableBindingSource.AddNew()
Try
Me.Validate()
Me.TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Database1DataSet)
MsgBox("Profil wurde gespeichert!")
Me.Hide()
Catch ex As Exception
End Try
End Sub
结束班
正如你所看到的,我已经搞砸了一些注释行和私人/公共声明, 希望能解决这个问题。当接受form2上的输入时,datagrid会创建一个新行,但不会存储信息。我怎样才能让它发挥作用?
答案 0 :(得分:0)
尝试使用此代码:
If Form1.DataGridView1.RowCount <> 0 Then
Form1.DataGridView1.Rows(0).Selected = True
Dim valueOfFirstRowFirstColumn As String = Form1.DataGridView1.SelectedCells.Item(0).Value
MsgBox(valueOfFirstRowFirstColumn)
End If
希望这有帮助