Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ListChangedType.Reset
 

ListChangedType.Reset

Hello,

I am watching a DataView. I am not using it for purpose of Binding but for updating other data structures.

I wanted to know more about the ListChangeType.Reset type in the ListChange event.
Specifically, I would like to know if Reset event may skip other ListChangeTypes. I mean, if I am watching ItemAdded/Changed/Moved/Deleted, do I need to watch a reset event?

What is the use case for a Reset event for a person who is already watching individual items?

Thanks in advance.

Please help.

SD
livedotnet  Thursday, January 08, 2009 8:31 PM
Hi livedotnet,

Ok, I got to know what you want to confirm. Indeed the "ItemAdeed/Changed/Moved/Deleted" were not bound to happen. If we define a data source type which implements IBindingList interface. We can decide in which method(such as AddItem, deleteItem operation) to fire the ListChanged event and pass the changed type. I have pasted some links in my previous post. Please click into IBindingList Interface, there is code sample in it which you can see how to fire the ListChanged event whenever need.

There are also data source types which already implements the IBindingList interfaces for you, and they will fire the appropriate event in their implementation of the Interface Method. Take DataView for example, I get the source code of the AddNew method through reflector. You can see it will fire the ListChanged event and pass "ItemAdded" event arguments.
publicvirtualDataRowViewAddNew()
{
DataRowViewview2;
IntPtrptr;
Bid.ScopeEnter(outptr,"<ds.DataView.AddNew|API>%d#\n",this.ObjectID);
try
{
this.CheckOpen();
if(!this.AllowNew)
{
throwExceptionBuilder.AddNewNotAllowNull();
}
if(this.addNewRow!=null)
{
this.rowViewCache[this.addNewRow].EndEdit();
}
this.addNewRow=this.table.NewRow();
DataRowViewview=newDataRowView(this,this.addNewRow);
this.rowViewCache.Add(this.addNewRow,view);
this.OnListChanged(newListChangedEventArgs(ListChangedType.ItemAdded,this.IndexOf(view)));
view2=view;
}
finally
{
Bid.ScopeLeave(refptr);
}
returnview2;
}

So don't worry these individual events will not be fired if the controls are bound to the dataTable object. If the data source type is implemented by your own, you will have more control in when and where to fire the ListChanged event.


Best regards,
Bruce Zhou



Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Thursday, January 15, 2009 8:13 AM
Hi livedotnet,

The ListChangedType enumeration covers all the types of list changes. ListChangedType.Reset is a special one. The Reset fi indicates the list has been widely changed. And all the listener controls will be notified and refresh their values. As we can see from the MSDN document, when we call the ApplySort and RemoveSort method, we need to set the ListChangedType to Reset value.

So if your application needs function like sorting, you will be interersted with the Reset event.

I've found several articles from MSDN for your reference. Please check out the following links.

If you have any further problem, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Tuesday, January 13, 2009 7:43 AM
Thanks Bruce for your reply.

But my question is only partly answered. I would also want to know, if all the individual item related events i.e. ItemAdded/Changed/Moved/Deleted are always guarenteed to happen and would never be skipped by the API and instead fire a Reset type event? I have not observed this yet, but was wondering if there was any possibility of firinga Reset type event and skipItemAdded/Changed/Moved/Deleted type ListChangedEvent altogether in unusual/unknown cases . I ask this as I do not want to get more updates than necessary and watch only limited events, accurately.

Thanks for any help provided.

Please help.

SD
livedotnet  Tuesday, January 13, 2009 6:30 PM
Hi livedotnet,

As I can understand, you want to avoid getting more updates than necessary. I don't know why you want to avoid ItemAdded/Changed/Moved/Deleted type ListChangedEvent. These are the changed type enumeration which we get from the change of the DataSource. If you want to avoid uncessary updates, you can evaluate the ListChanged Type in the ListChanged event handler and do the corresponding update.

To describe my idea in the pseudocode.

void DataSource_ListChanged(object sender, ListChangedEventArgs e)
{
if(e.ListChangedType == ListChangedType.Reset)
{
Updates();
}
else if(e.ListChangedType ==ListChangedType.ItemAdded ||............)
{
Other();
}
}

So as you can see, any change fired the ListChanged event we can get the type from the ListChangedEventArgs parameter, and we can decide which types we need to care and to deal with.

If I've misunderstood you, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Wednesday, January 14, 2009 2:21 AM
Thanks Bruce for your reply.

I wished to know exactly the oppposite of what you have replied. I want to watch all those individual item related event. What I do not want to watch is the Reset event. Hence, I looked up all over the web including MSDN etc and found no evidence stating that these events were always bound to happen and that a "Reset" event wont replace any or all of these events.

Please confirm the above. Thanks for replying to my queries as I think my doubt may be small enough.

Please help.

SD


livedotnet  Wednesday, January 14, 2009 2:08 PM
Hi livedotnet,

Ok, I got to know what you want to confirm. Indeed the "ItemAdeed/Changed/Moved/Deleted" were not bound to happen. If we define a data source type which implements IBindingList interface. We can decide in which method(such as AddItem, deleteItem operation) to fire the ListChanged event and pass the changed type. I have pasted some links in my previous post. Please click into IBindingList Interface, there is code sample in it which you can see how to fire the ListChanged event whenever need.

There are also data source types which already implements the IBindingList interfaces for you, and they will fire the appropriate event in their implementation of the Interface Method. Take DataView for example, I get the source code of the AddNew method through reflector. You can see it will fire the ListChanged event and pass "ItemAdded" event arguments.
publicvirtualDataRowViewAddNew()
{
DataRowViewview2;
IntPtrptr;
Bid.ScopeEnter(outptr,"<ds.DataView.AddNew|API>%d#\n",this.ObjectID);
try
{
this.CheckOpen();
if(!this.AllowNew)
{
throwExceptionBuilder.AddNewNotAllowNull();
}
if(this.addNewRow!=null)
{
this.rowViewCache[this.addNewRow].EndEdit();
}
this.addNewRow=this.table.NewRow();
DataRowViewview=newDataRowView(this,this.addNewRow);
this.rowViewCache.Add(this.addNewRow,view);
this.OnListChanged(newListChangedEventArgs(ListChangedType.ItemAdded,this.IndexOf(view)));
view2=view;
}
finally
{
Bid.ScopeLeave(refptr);
}
returnview2;
}

So don't worry these individual events will not be fired if the controls are bound to the dataTable object. If the data source type is implemented by your own, you will have more control in when and where to fire the ListChanged event.


Best regards,
Bruce Zhou



Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Thursday, January 15, 2009 8:13 AM
Hi Livedotnet,

Do you still have any problems? Is so, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Friday, January 16, 2009 9:34 AM
Thanks for your time Bruce.

As I have mentioned in the first question itself, I do not want to use this for Binding.
I do not want to fire any DataView events myself.


Consider that I am just a user of some events of the data view. I would like to know if the "Reset" is fired "along with" other events or can it be fired "instead of" other events by the Microsoft DataView API? Here the term "other events" means "Item Added/Changed/Deleted/Moved".

Thank you,
SD
livedotnet  Tuesday, January 20, 2009 10:11 PM
Hi livedotnet,

For DataView object, the "Reset" event isn't fired along with other events, and we haven't the access to change internal behavior of the DataView object.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Wednesday, January 21, 2009 2:08 AM

Hi Bruce,

I have a related question, hope if it's alright if I ask in the same thread.

I have a parent form and a child form.
The child form has a DataGridView and it shows alerts.
The control's datasource is a static dataview which I update from the parent when necessary.
Depending on certain criteria, some alerts needs to be disabled and some can be updatable.

This is what I have in the child,

private void ExceptionsAlertsForm_Load(object sender, EventArgs e)
{
...
dgvResults.DataSource = resultsTable.DefaultView;
DisableAlerts();
}

private void dgvResults_Sorted(object sender, EventArgs e)
{
DisableAlerts();
}

But, when I changed the static table 'resultsTable' from the parent, the disabled rows in the child form got enabled.
I wanted to call the DisableAlerts() methodafter I've done changes from the parent.

So, this is what I did,
private void dgvResults_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
DisableAlerts();
}

But this event fires for every add/delete/move etc I perform on the static table,which is a hit on performance for me.
How can I call this method just once after I do all the changes to the static table from theparent?

Appreciate any insights/suggestions on, may be any other way of doing it or modifying the existing.

Dinith

DinithT  Friday, April 17, 2009 12:05 PM
Please start a new thread for this question.


Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Friday, April 17, 2009 12:08 PM

You can use google to search for other answers

Custom Search

More Threads

• Merging arrays
• COMBOBOX many-to-many
• How to make the DataGridView to have rows for cols
• 2 Datagridviews: drag drop 2 columns only
• SqlDataAdapter wont refresh based on the given stored procedure parameter / Datagrid also
• Plss Help !!!
• Last Editted Cell Position & Datagrid cell value
• No scroll events in ListBox/ComboBox etc - why?!?!?
• Binding control property used with DataGridTextBoxColumn in datagrid
• Generating dataset from XML schema