如何覆盖 DevExpress GridView 删除
我有一个表 (myTable
),我想从中删除行,但不删除它们。我使用 myTable.ActiveFlag
使它们过期。因此,当我从 myTable
中“删除”一行时,我想运行 UPDATE myTable SET ActiveFlag = 0 WHERE 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从我的角度来看,您选择了实现此功能的正确方法。
From my point of view, you have chosen a correct way of implementing this feature.
这是我的最终代码的基本版本:
Here is a basic version of my final code: