Override add on bindinglist

  • Thread starter Thread starter Ste
  • Start date Start date
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.
 
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.
 
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:
 
Back
Top