From: Lothar Behrens on
Hi,

I am using .NET 3.5 and object binding. A grid has one row and I add a
new row by a separate button.
The button_Click handler uses this code to refresh the binding:

private void buttonNeuerKaeufer_Click(object sender, EventArgs
e)
{
if (bindingObjektMode)
{
ov_mock.createRechnungsempfaenger();
bindRechnungsempfaengerGrid(ov_mock);
}
}

private void bindRechnungsempfaengerGrid(IObjektverkauf ov)
{
System.Console.WriteLine("Anzahl Rechnungsempfaenger: " +
ov.Rechnungsempfaenger.Count());
IEnumerable<IRechnungsempfaenger> bo =
ov.Rechnungsempfaenger;
if (RechnungsempfaengerDataGridView.DataSource != null)
this.BindingContext[RechnungsempfaengerDataGridView.DataSource].SuspendBinding();
this.RechnungsempfaengerDataGridView.DataSource = null;
this.RechnungsempfaengerDataGridView.DataSource = bo;

this.BindingContext[RechnungsempfaengerDataGridView.DataSource].ResumeBinding();
}

....

Then I see the first cell at top left selected. After that I shift +
select with the mouse the cell under that selected.
It is the new row. Then I get the exception and the following stack
trace.

In a simple LinqToSQL based grid I do not have this problem.

What am I doing wrong?

Thanks

Lothar

bei System.Collections.ArrayList.get_Item(Int32 index)
bei
System.Windows.Forms.DataGridViewColumnCollection.DisplayInOrder(Int32
columnIndex1, Int32 columnIndex2)
bei
System.Windows.Forms.DataGridView.UpdateSelectedCellsBlock(Int32
anchorColumnIndex, Int32& oldEdgeColumnIndex, Int32
newEdgeColumnIndex, Int32 anchorRowIndex, Int32& oldEdgeRowIndex,
Int32 newEdgeRowIndex)
bei System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo
hti, Boolean isShiftDown, Boolean isControlDown)
bei
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs
e)
bei System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
bei System.Windows.Forms.Control.WmMouseDown(Message& m,
MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.DataGridView.WndProc(Message& m)
bei
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
bei
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
bei
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
bei
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(Form mainForm)
bei Provisionsabrechnung.Program.Main() in C:\Users\l.behrens
\Projekte\Provisionsabrechnung\Provisionsabrechnung\Program.cs:Zeile
20.