我在表單上有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
不知道的Presenter
。 View
只是在用戶操作時觸發事件。
private void btnDelete_Click(object sender, EventArgs e)
{
OnDeleteAttendance(sender, e);
}
編輯:我的網格有幾列像AttendanceID
,EmployeeID
,Name
,InDateTime
,OutDateTime
等等,我使用視圖一個公共屬性,從演示
public BindingList<IAttendance> AttendanceGrid
{
Set { dgvAttendance.DataSource = Value; };
}
請分享您的網格標記 – malkam