vb 2005的怪现象
Private Sub 删除行按钮_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 删除行按钮.ClickIf DataGridView1.Rows.Count = 1 Then
DataGridView1.CurrentCell = DataGridView1(0, cellrow)
Else
Me.报单dataset.Tables("差旅单").Rows(DataGridView1.CurrentRow.Index).Delete() '删除datagirdview中指定的行
Dim srow As Integer
Dim i As Integer
srow = DataGridView1.Rows.Count - 1
For i = 0 To srow - 1
DataGridView1(0, i).Value = i + 1
报单BindingSource.EndEdit()
Next i
End If
CurrentcellDirty = True
GetSumData()
End Su
执行以上代码时,必需删除一行之后要更新一次数据库,否则就不能删除下一行.
另外执行以下代码
Private Sub 插入新行按钮_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 插入新行按钮.Click
Dim newrow As DataRow
newrow = Me.报单dataset.Tables("差旅单").NewRow
'DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.CurrentRow.Index)
Me.报单dataset.Tables("差旅单").Rows.InsertAt(newrow, DataGridView1.CurrentRow.Index)
Dim srow As Integer
Dim i As Integer
srow = DataGridView1.Rows.Count - 1
For i = 0 To srow - 1
DataGridView1(0, i).Value = i + 1
DataGridView1.CurrentCell = DataGridView1(0, i)
报单BindingSource.EndEdit()
Next i
CurrentcellDirty = True
GetSumData()
End Sub
插入一行后不要更新到数据库,更新时不提示任何错误.
请大家帮看看,急啊
在这里谢谢各位啦!