473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

BindingList<> notification before delete?

Hi,

A datagrid has its DataSource set to a BindingList<CustomClass>. While the
ListChanged event fires AFTER a deletion, I am looking for a simple way to
be notified BEFORE the item would be effectively deleted (for performing
extra check and cleanup). Is there a simple trick I miss, because I don't
know how to do that, except to maintain TWO lists, and compare them in the
ListChanged event (to detect which item is now missing).

Simplified examples of what I try to get :
- check before deleting if there will be at least one 'admin' left
- free C# ressources of the CustomClass item just to be deleted (as a
cascade delete would have done for database records)
Thanks,

Vanderghast, Access MVP
Dec 6 '06 #1
4 5325
Well, you could always write a generic class that inherits from
BindingList<T>, and override the RemoveItem(int) method to fire a new
event before calling base.RemoveItem() [perhaps with a CancelEventArgs
implementation]. This would allow the subscriber to obtain the item (by
index) prior to the delete.

Marc

Dec 6 '06 #2
Hi,
Hoping the datagridview internally calls that method... I'll try it
tomorrow, anyhow, and see what happens.

Vanderghast, Access MVP
"Marc Gravell" <ma**********@gmail.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
Well, you could always write a generic class that inherits from
BindingList<T>, and override the RemoveItem(int) method to fire a new
event before calling base.RemoveItem() [perhaps with a CancelEventArgs
implementation]. This would allow the subscriber to obtain the item (by
index) prior to the delete.

Marc

Dec 7 '06 #3
Actually, I believe it will call the IList.RemoveAt(int) method, which
is in this case gets forwarded to the Collection<Tbase-class of
BindingList<T>, so yes: overriding this method should do what you need.

Only one way to find out ;-p

Marc

Dec 7 '06 #4
Hi,

and indeed, it works like a charm.
Thanks.
"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
Actually, I believe it will call the IList.RemoveAt(int) method, which
is in this case gets forwarded to the Collection<Tbase-class of
BindingList<T>, so yes: overriding this method should do what you need.

Only one way to find out ;-p

Marc

Dec 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Frank VDL | last post by:
Hi, To be able to show my objects in a Grid, I've inherited my list implementation from BindingList<T>. The problem is that de objects in this list are created/changed/deleted in different...
4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
0
by: Chris Dunaway | last post by:
I posted this to the xml group but got no responses, so I thought I'd try here. I have the following small class which inherits from the generic List class: public class FoodItemList :...
0
by: AndyM | last post by:
I have tried to create an object that is a binding list where the value of T varies and so cannot be hard coded. I used the override for CreateInstance which takes a type object. The Type was...
5
by: Mike Surcouf | last post by:
Hi All I have a stored procedure wrapper that returns Collection<T>. The wrapper is generated by codesmith so I don't really want to start altering it. I need to use this collection in a...
1
by: Merk | last post by:
I need to show users a list of "Person" attributes in a grid. I currently have a custom "Person" class that mostly has a bunch of string properties (firstName, lastName, etc). While I want to...
2
by: csharpula csharp | last post by:
Hello, I would like to know what is better for data binding and serialization purposes ArrayList or List<? Thank you! *** Sent via Developersdex http://www.developersdex.com ***
1
by: jehugaleahsa | last post by:
Hello: I would like to perform an action on an item when it is removed from a BindingList<T>. However, I can only find out how to get the old index of the item, which doesn't really help me. ...
3
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.