UltraWinGrid删除最高记录而不是选定的记录

时间:2016-07-05 12:41:37

标签: vb.net infragistics delete-row ultragrid ultrawingrid

我有一个我可以选择行的超浪花,并且需要能够删除突出显示的行。目前,它调用我编写的数据库SQL查询,但不是删除我选择的行中的记录,而是删除顶行中的记录。任何人都可以找出原因吗?

    Private Sub btnDeleteIncident_Click(sender As Object, e As EventArgs) Handles btnDeleteIncident.Click

    Try
        Dim rowValue = ugHistory.Selected.Rows

        Dim rowToDelete = ugHistory.Rows(0).Cells(0).Value.ToString

        Dim removeIncident As MsgBoxResult
        removeIncident = MsgBox("Are you sure you wish to delete this incident?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")

        If removeIncident = MsgBoxResult.Yes Then

            Database.deleteIncident(rowToDelete)

            txtClientSave.Text = ""
            rtbProblem.Text = ""
            rtbSolution.Text = ""
            dtpStart.Value = Date.Today
            dtpEnd.Value = Date.Today
            dtpStartTime.Value = DateTime.Now
            dtpEndTime.Value = DateTime.Now
            cboxSolved.Checked = False
            btnUpdate.Hide()
            btnSave.Show()

        ElseIf removeIncident = MsgBoxResult.No Then
            loadIncidents()
        End If

    Catch Ex As Exception
        MsgBox("No incidents to delete")
    End Try

    loadIncidents()

End Sub

数据库SQL查询;

Public Shared Sub deleteIncident(ByVal supportID As Integer)

    Connect()

    Dim Dc As New OleDbCommand
    Dc.Connection = Con

    Dc.CommandText = "DELETE * FROM tblIncidents WHERE([supportID] = " & supportID & ")"

    Dc.ExecuteNonQuery()
    Disconnect()

End Sub

1 个答案:

答案 0 :(得分:0)

您从网格的第一行而不是当前活动行获取rowToDelete的值

我建议你改变这一行

 Dim rowToDelete = ugHistory.Rows(0).Cells(0).Value.ToString

 Dim rowToDelete = ugHistory.ActiveRow.Cells(0).Value.ToString

此外,在处理像'ActiveRow'这样的引用对象时,最好遵循安全的方法,因此在运行代码之前添加一个有效的测试 ActiveRow

 if ugHistory.ActiveRow Is Nothing Then 
     Return
 End If
 Dim rowToDelete = ugHistory.ActiveRow.Cells(0).Value.ToString