我有一個表(myTable
),我想從中刪除行但不刪除它們。我將通過使用myTable.ActiveFlag
到期。所以當我從myTable
「刪除」一行時,我想運行UPDATE myTable SET ActiveFlag = 0 WHERE id = @rowId
。我如何重寫DevExpress GridView刪除
什麼是使用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
考慮發佈您的解決方案作爲一個答案,因此可能是未來的讀者有所幫助。 – BartoszKP 2014-01-22 23:30:55