如何覆盖DevExpress GridView删除

如何覆盖DevExpress GridView删除,gridview,devexpress,gridcontrol,Gridview,Devexpress,Gridcontrol,我有一个表(myTable),我想从中删除行,但不想删除它们。我使用myTable.ActiveFlag使它们过期。因此,当我从myTable中“删除”一行时,我希望运行updatemytable SET-ActiveFlag=0,其中id=@rowId 使用DevExpressGridcontrol和GridView进行此操作的最佳方法是什么 我目前: Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal se

我有一个表(
myTable
),我想从中删除行,但不想删除它们。我使用
myTable.ActiveFlag
使它们过期。因此,当我从
myTable
中“删除”一行时,我希望运行
updatemytable SET-ActiveFlag=0,其中id=@rowId

使用DevExpress
Gridcontrol
GridView
进行此操作的最佳方法是什么

我目前:

Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
    If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
        //'TODO: Remove Row
    End If
    e.Handled = True
End Sub
我想在这里运行一个存储过程或SQL语句,但是有更简单或更合适的方法吗



以下是我的最终代码的基本版本:

Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
    If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
        Dim iMyTableId As Int32 = 0

        iMyTableId = gvMyTableMaintenance.GetFocusedRowCellValue("id")

        Using conn As New SqlConnection(MyConnectionString)
            Using lCmd As New SqlCommand()
                Try
                    lCmd.Connection = conn
                    lCmd.CommandType = CommandType.StoredProcedure
                    lCmd.CommandText = "ExpireFromMyTable"
                    lCmd.Parameters.AddWithValue("@myTableId", iMyTableId)
                    conn.Open()
                    lCmd.ExecuteNonQuery()
                    conn.Close()

                    //'Need to delete from 
                    gvMyTableMaintenance.DeleteRow(gvMyTableMaintenance.FocusedRowHandle)
                Catch ex As Exception
                    //'Handle Exception
                End Try
            End Using
        End Using
    End If
    e.Handled = True
End Sub
Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
    If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
        Dim iMyTableId As Int32 = 0

        iMyTableId = gvMyTableMaintenance.GetFocusedRowCellValue("id")

        Using conn As New SqlConnection(MyConnectionString)
            Using lCmd As New SqlCommand()
                Try
                    lCmd.Connection = conn
                    lCmd.CommandType = CommandType.StoredProcedure
                    lCmd.CommandText = "ExpireFromMyTable"
                    lCmd.Parameters.AddWithValue("@myTableId", iMyTableId)
                    conn.Open()
                    lCmd.ExecuteNonQuery()
                    conn.Close()

                    //'Need to delete from 
                    gvMyTableMaintenance.DeleteRow(gvMyTableMaintenance.FocusedRowHandle)
                Catch ex As Exception
                    //'Handle Exception
                End Try
            End Using
        End Using
    End If
    e.Handled = True
End Sub

在我看来,您选择了实现此功能的正确方法。

以下是我最终代码的基本版本:

Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
    If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
        Dim iMyTableId As Int32 = 0

        iMyTableId = gvMyTableMaintenance.GetFocusedRowCellValue("id")

        Using conn As New SqlConnection(MyConnectionString)
            Using lCmd As New SqlCommand()
                Try
                    lCmd.Connection = conn
                    lCmd.CommandType = CommandType.StoredProcedure
                    lCmd.CommandText = "ExpireFromMyTable"
                    lCmd.Parameters.AddWithValue("@myTableId", iMyTableId)
                    conn.Open()
                    lCmd.ExecuteNonQuery()
                    conn.Close()

                    //'Need to delete from 
                    gvMyTableMaintenance.DeleteRow(gvMyTableMaintenance.FocusedRowHandle)
                Catch ex As Exception
                    //'Handle Exception
                End Try
            End Using
        End Using
    End If
    e.Handled = True
End Sub
Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
    If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
        Dim iMyTableId As Int32 = 0

        iMyTableId = gvMyTableMaintenance.GetFocusedRowCellValue("id")

        Using conn As New SqlConnection(MyConnectionString)
            Using lCmd As New SqlCommand()
                Try
                    lCmd.Connection = conn
                    lCmd.CommandType = CommandType.StoredProcedure
                    lCmd.CommandText = "ExpireFromMyTable"
                    lCmd.Parameters.AddWithValue("@myTableId", iMyTableId)
                    conn.Open()
                    lCmd.ExecuteNonQuery()
                    conn.Close()

                    //'Need to delete from 
                    gvMyTableMaintenance.DeleteRow(gvMyTableMaintenance.FocusedRowHandle)
                Catch ex As Exception
                    //'Handle Exception
                End Try
            End Using
        End Using
    End If
    e.Handled = True
End Sub

考虑把你的解决方案作为一个答案,这样它会对未来的读者有所帮助。