datagrid doesn't reflect changes in data (unless datatable)

P

Peter Bladh

Hi!

After a tip from Alex Feinman I manage to databind a datagrid to an
arraylist (thanks!). But the datagrid doesn't reflect changes in the
arraylist, unless I do the following

dg.DataSource = null;
dg.DataSource = myArrayList;

.... which doesn't seem very effective.
Is there a better way?


Regards
Peter Bladh
 
P

Peter Foot [MVP]

ArrayList does not expose the IBindingList interface which expose the Event
used to react to changes in the datasource. The only way to refresh the grid
therefore is to manually force it to update using the method described
below.

Peter
 
P

Peter Bladh

Thank you for your answer!

Anothor disadvantage with

is that the datagrid won't keep the "scroll location" - if the user has
scrolled down and the datagrid gets updated it will "scroll up". That kind
of behavior will probably upset the users...:)
Is there a way to keep the "scroll location"?


Regards / Peter Bladh
 
D

Don Strenczewilk

Something basically like the following (but I use a DataTable) works for me:

// Save the current item's ID
int oldPsId = this.GetCurrentPackingSlipId(context);
....
dg.DataSource = null;
dg.DataSource = myArrayList;
....
if (oldPsId != 0) {
// Find the index of the old psid in the ArrayList
i = ArrayListIndexOfID(oldPsId); // I used datatable.find here.
if (i >= 0) {
dg.CurrentRowIndex = i;
dg.Select(i);
}
}
 

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