Override add on bindinglist

S

Ste

Good morning,
I have a bindinglist of my custom objects and need to check, before
adding items, if an item exists in list and then cancel inserting.

I have tried to create an object that inherits from
bindinglist<mycustomobject> but I cannot override Add method.

This because this bindinglist is a datasource for a datagrid and need to
avoid to insert duplicated instances.

Thanks.
Stefano.
 
P

Pavel Minaev

Good morning,
I have a bindinglist of my custom objects and need to check, before
adding items, if an item exists in list and then cancel inserting.

I have tried to create an object that inherits from
bindinglist<mycustomobject> but I cannot override Add method.

You shouldn't override Add, you should override the protected
InsertItem method. It will be called for any operation that inserts a
new item into the list, be it Add or Insert.
 
S

Ste

Ok, but now I have tried to override EndNew method to find in the
innerlist if item was inserted (because only when I commit I have all
data to use for search) and then cancel it using CancelNew. The problem
is that ItemIndex parameter is alwais -1.

Thank you.
Stefano.

Pavel Minaev ha scritto:
 

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