如何覆盖 DevExpress GridView 删除

发布于 2024-09-09 16:27:23 字数 2007 浏览 4 评论 0原文

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

使用 DevExpress GridcontrolGridView 执行此操作的最佳方法是什么?

我目前:

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

I've got a table (myTable) that I want to remove rows from but not delete them. I'm expiring them by using an myTable.ActiveFlag. So when I "delete" a row from myTable, I'd like to run UPDATE myTable SET ActiveFlag = 0 WHERE id = @rowId.

What is the best way to do this using a DevExpress Gridcontrol with GridView?

I've currently:

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

I was thinking of running a stored proc or an SQL statement here, but is there an easier or more appropriate way to do this?


Here is a basic version of my final code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花落人离去 2024-09-16 16:27:23

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

From my point of view, you have chosen a correct way of implementing this feature.

摇划花蜜的午后 2024-09-16 16:27:23

这是我的最终代码的基本版本:

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

Here is a basic version of my final code:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文