I can't reproduce it.
I've added to a form:
datagridview
orderdetailscollection
bindingsource
I've set AllowRemove to true on the orderdetailscollection
I've bound 2 event handlers to the grid: one for deleting row and one for deleted row (see code below).
Note: I fill the collection added to the form, this is essential, as I have set the allowremove property on THAT collection to true.
Anyway, it works here... so why it doesn't work in your application is a mistery to me...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NWTest.HelperClasses;
namespace Tester
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
orderDetailsCollection1.GetMulti((OrderDetailsFields.OrderId == 10254));
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("AllowRemove on bindingsource: " + bindingSource1.AllowRemove.ToString());
}
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
MessageBox.Show("DeletingRow");
}
private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
MessageBox.Show("DeletedRow");
}
}
}
form:
namespace Tester
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.orderDetailsCollection1 = new NWTest.CollectionClasses.OrderDetailsCollection();
this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.orderIdDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.productIdDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.unitPriceDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.discountDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.orderIdDataGridViewTextBoxColumn,
this.productIdDataGridViewTextBoxColumn,
this.unitPriceDataGridViewTextBoxColumn,
this.quantityDataGridViewTextBoxColumn,
this.discountDataGridViewTextBoxColumn});
this.dataGridView1.DataSource = this.bindingSource1;
this.dataGridView1.Location = new System.Drawing.Point(13, 13);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(802, 482);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.dataGridView1_UserDeletingRow);
this.dataGridView1.UserDeletedRow += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_UserDeletedRow);
//
// orderDetailsCollection1
//
this.orderDetailsCollection1.ActiveContext = null;
this.orderDetailsCollection1.AllowEdit = true;
this.orderDetailsCollection1.AllowNew = true;
this.orderDetailsCollection1.AllowRemove = true;
this.orderDetailsCollection1.Capacity = 0;
this.orderDetailsCollection1.ConcurrencyPredicateFactoryToUse = null;
this.orderDetailsCollection1.DoNotPerformAddIfPresent = true;
this.orderDetailsCollection1.EntityFactoryToUse = new NWTest.FactoryClasses.OrderDetailsEntityFactory();
this.orderDetailsCollection1.EntityValidatorToUse = null;
this.orderDetailsCollection1.MaxNumberOfItemsToReturn = ((long)(0));
this.orderDetailsCollection1.SortClauses = null;
this.orderDetailsCollection1.SupportsSorting = false;
this.orderDetailsCollection1.SuppressClearInGetMulti = false;
this.orderDetailsCollection1.Transaction = null;
this.orderDetailsCollection1.ValidatorToUse = null;
//
// bindingSource1
//
this.bindingSource1.DataSource = this.orderDetailsCollection1;
//
// orderIdDataGridViewTextBoxColumn
//
this.orderIdDataGridViewTextBoxColumn.DataPropertyName = "OrderId";
this.orderIdDataGridViewTextBoxColumn.HeaderText = "OrderId";
this.orderIdDataGridViewTextBoxColumn.Name = "orderIdDataGridViewTextBoxColumn";
//
// productIdDataGridViewTextBoxColumn
//
this.productIdDataGridViewTextBoxColumn.DataPropertyName = "ProductId";
this.productIdDataGridViewTextBoxColumn.HeaderText = "ProductId";
this.productIdDataGridViewTextBoxColumn.Name = "productIdDataGridViewTextBoxColumn";
//
// unitPriceDataGridViewTextBoxColumn
//
this.unitPriceDataGridViewTextBoxColumn.DataPropertyName = "UnitPrice";
this.unitPriceDataGridViewTextBoxColumn.HeaderText = "UnitPrice";
this.unitPriceDataGridViewTextBoxColumn.Name = "unitPriceDataGridViewTextBoxColumn";
//
// quantityDataGridViewTextBoxColumn
//
this.quantityDataGridViewTextBoxColumn.DataPropertyName = "Quantity";
this.quantityDataGridViewTextBoxColumn.HeaderText = "Quantity";
this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn";
//
// discountDataGridViewTextBoxColumn
//
this.discountDataGridViewTextBoxColumn.DataPropertyName = "Discount";
this.discountDataGridViewTextBoxColumn.HeaderText = "Discount";
this.discountDataGridViewTextBoxColumn.Name = "discountDataGridViewTextBoxColumn";
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button1.Location = new System.Drawing.Point(13, 512);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Fetch";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(136, 511);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(827, 547);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn orderIdDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn productIdDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn unitPriceDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn discountDataGridViewTextBoxColumn;
private System.Windows.Forms.BindingSource bindingSource1;
private NWTest.CollectionClasses.OrderDetailsCollection orderDetailsCollection1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}