2014-06-28 13 views
0

我在表單上有DataGridView,並且我在Presenter中將BindingList綁定到Grid如何與演示者溝通DataGridView行索引

public AttendancePresenter(IAttendance model, IAttendanceView view, IDataService dataService, IMessageService messageService) : base(messageService) 
{ 
    _BindingAttendanceList = new BindingList<IAttendance>(); 
    _View.AttendanceGrid = _BindingAttendanceList; 
} 

現在我想從網格中刪除選定的行,當我按下刪除按鈕(並且此更改應該更新回數據庫)。我的問題是我應該怎麼通知我要在網格中刪除特定的行/項目Presenter?如果演示者知道它可以從BindingList中找到已刪除的項目,並從數據庫中刪除相同的記錄。 (ID字段AttendanceID場可以在這方面使用)

注:View不知道的PresenterView只是在用戶操作時觸發事件。

private void btnDelete_Click(object sender, EventArgs e) 
{ 
    OnDeleteAttendance(sender, e); 
} 

編輯:我的網格有幾列像AttendanceIDEmployeeIDNameInDateTimeOutDateTime等等,我使用視圖一個公共屬性,從演示

public BindingList<IAttendance> AttendanceGrid 
{ 
    Set { dgvAttendance.DataSource = Value; }; 
} 
+0

請分享您的網格標記 – malkam

回答

1
定格

如果我理解正確的是什麼,你基本上是問的是如何通過要從查看鐠刪除的項目的ID Esenter

有2種典型的方式,你可以這樣做:

  1. 創建用來得到你想要刪除的項目的ID查看接口的屬性。

    public int IdToDelete 
    { 
        get 
        { 
         // logic to get the id of the item you want to delete 
        } 
    } 
    

    通過這種方式,您可以在Presenter中訪問要刪除的項目的ID。

  2. 另一種方法是擴展EventArgs類並添加另一個屬性來存儲項目的ID,但我認爲這將是一個傳遞單個值的矯枉過正。