Unexpected results from BindingSource.ResetCurrentItem()

G

Geoff

Hi folks

Calling BindingSource.ResetCurrentItem() is changing the
BindingSource.Position in a way I don't understand.

If I'm understanding the docs correctly, ResetCurrentItem()
should simply trigger an event which causes controls to
refresh with the values of the current item with the index
BindingSource.Position. This is not what I'm seeing.

I'm trying to copy values from the current item to a new
item. In the code below, there are 400 items in the
underlying data (a strongly typed DataTable), and I'm trying
to copy the 100th item.
if( editAction == EditAction.Copy )
{
// bindingSource.Position == 99 as expected

DataRowView fromRow = (DataRowView)bindingSource.Current;

string label =
fromRow["label"].ToString().Clone().ToString();

bindingSource.AddNew();

// bindingSource.Position == 400 as expected

DataRowView toRow = (DataRowView)bindingSource.Current;
toRow["label"] = label;

// Reset to update the control

bindingSource.ResetCurrentItem();

// bindingSource.Position == 97, expected it to be 400
}

I don't understand why the Position is jumping to what seems
to be an arbitrary value.

I'm a C# newbie, so please forgive any basic errors. I'm at
a bit of a loss with this one, so any pointers would be much
appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top