Vb.net Net-DataGridView,在创建新行时,以前的条目将变为空
这是我的密码Vb.net Net-DataGridView,在创建新行时,以前的条目将变为空,vb.net,Vb.net,这是我的密码 Dim TMID As Integer = -1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TMID = TMID + 1 If TMID > 0 Then Form2.DataGridView1.Rows.Add() End If Form2.DataGridView1.Rows(TMID).Cells(
Dim TMID As Integer = -1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TMID = TMID + 1
If TMID > 0 Then
Form2.DataGridView1.Rows.Add()
End If
Form2.DataGridView1.Rows(TMID).Cells(0).Value = TMID + 1
Form2.DataGridView1.Rows(TMID).Cells(1).Value = Me.TextBox1.Text
Form2.DataGridView1.Rows(TMID).Cells(2).Value = "-"
Form2.DataGridView1.Rows(TMID).Cells(3).Value = "-"
Form2.DataGridView1.Rows(TMID).Cells(4).Value = Me.TextBox2.Text
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End Sub
末级
单击按钮1(添加按钮)一段时间后,它将如下所示;
我不熟悉VB.net:(我想你想做的是,每次单击“添加”按钮时,先前保存的数据都会丢失。为此,我相信,每次单击“添加”按钮时,都会将数据保存到数据库中。在Form2.DataGridView1中,从数据库中添加数据。:)查看上的
DataGridView.Rows
属性
您可以像这样一次添加该行的所有项
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TMID = TMID + 1
Form2.DataGridView1.Rows.Add(TMID + 1, "test", "-", "-", "Test")
End Sub