开发者

How can I override the DevExpress GridView delete

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


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜