2010-07-15 63 views
0

我有一個表(myTable),我想從中刪除行但不刪除它們。我將通過使用myTable.ActiveFlag到期。所以當我從myTable「刪除」一行時,我想運行UPDATE myTable SET ActiveFlag = 0 WHERE id = @rowId我如何重寫DevExpress GridView刪除

什麼是使用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 
+0

考慮發佈您的解決方案作爲一個答案,因此可能是未來的讀者有所幫助。 – BartoszKP 2014-01-22 23:30:55

回答

0

這裏是我的最終代碼基本版本:

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

這是每個請求添加的。 – 2014-02-10 15:44:43

2

從我的角度來看,你選擇了實現這一功能的正確途徑。