problem with cancel addnew in winforms databinding using sorted/filtered list with csla 3.7.1.0

problem with cancel addnew in winforms databinding using sorted/filtered list with csla 3.7.1.0

Old forum URL: forums.lhotka.net/forums/t/7741.aspx


Reto posted on Wednesday, October 07, 2009

Dear Rocky

To cancel a addnew i used the mBindingSource.RemoveCurrent() statment.
This code fails with the csla 3.7.1.0 version with an 'index out of range' exeption in OriginalIndex() called from ICancelAddNew.cancelNew code.

void ICancelAddNew.CancelNew(int itemIndex)
{
ICancelAddNew can = _list as ICancelAddNew;
if (can != null)
can.CancelNew(OriginalIndex(itemIndex) );
else
_list.RemoveAt(OriginalIndex(itemIndex));
}

For my understanding, in this case, there is no originalIndex since the AddNew just added a new item to the end of the list.
When i replace the OriginalIndex(itemIndex) with itemIndex your code runs fine.

[winforms databinding, sorted/filtered EditableRootListBase, vs 2008 - vb, csla 3.7.1.0]

regards reto

RockfordLhotka replied on Wednesday, October 07, 2009

So you've done this:

  1. wrapped an EditableRootListBase collection with SortedBindingList
  2. bound it to a datagrid
  3. moved to the last row of the grid to add a new row
  4. pressed ESC to cancel the add

Is that accurate?

Reto replied on Wednesday, October 07, 2009

Dear Rocky

I have done this:

1. wrapped an EditableRootListBase collection with SortedBindingList
2. bound it to some textboxes
3. do some filtering
4. bindingsource.addnew
5. bindingsource.removeCurrent (to cancel the addNew)

The exeption is an argumentOutofRange-exeption in OriginalIndex() called from ICancelAddNew.endNew code in the sortedbindigList.cs resp. filterdbindingList.cs.

regards reto

ajj3085 replied on Thursday, October 08, 2009

As your last step, maybe you should be calling CancelEdit on the bindingsource?

Reto replied on Thursday, October 08, 2009

CancelEdit leave a ghost record (empty record) at the beginning of the list - so the only solution working for me so far (prior to 3.7.1.0) was to call removeCurrent.

RockfordLhotka replied on Thursday, October 08, 2009

The thing to do is to make sure you are doing whatever the datagrid does. That's the scenario ERLB is designed to support - anything outside that scenario might or might not work unless your code emulates the datagrid behavior.

Copyright (c) Marimer LLC