在我已经消耗了第一行之后,如何阻止DataGridView
控件触发每个选定行的事件?UserDeletingRow
这个网格绑定到我的 wcf-webservice 中的对象,我只想对所有应该删除的对象执行一次 delete 方法。
此事件处理程序为每个选定的行触发,它也总是触发“你真的要删除吗”-messageboxes:
private void Grid_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
switch (this.Type)
{
case AdminType.Channel:
List<Channel> channels = GrdChannel.SelectedRows.Cast<DataGridViewRow>()
.Select(row => (Channel)row.DataBoundItem).ToList();
e.Cancel = !Delete_Channels(channels);
break;
// other types ...
default:
break;
}
}
该方法在确认后调用webservice:
private bool Delete_Channels(List<Channel> channels)
{
var msg = string.Format("Do you really want to delete {0}?", channels.Count == 1 ? "this channel" : "these channels");
var title = channels.Count == 1 ? "Delete channel" : "Delete channels";
bool yes = MessageBox.Show(msg, title, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes;
if (yes)
{
using (var db = new ERP_ServiceClient())
db.DeleteChannels(channels, this.IdUser);
string message = string.Format("{0} deleted successfully: {1}"
, channels.Count == 1 ? "Channel" : "Channels"
, string.Join(",", channels.Select(p => p.Name)));
channelBindingSource.Remove(channels);
Main.ShowStatusMessage(message);
}
return yes;
}