471,330 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Override add on bindinglist

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<mycustomobjectbut 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.
Jul 22 '08 #1
2 5524
On Jul 22, 6:24*pm, Ste <sceru...@svilupso.itwrote:
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<mycustomobjectbut 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.
Jul 22 '08 #2
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:
On Jul 22, 6:24 pm, Ste <sceru...@svilupso.itwrote:
>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<mycustomobjectbut 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.
Jul 22 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dave Booker | last post: by
3 posts views Thread by Bryan | last post: by
5 posts views Thread by Mike Surcouf | last post: by
6 posts views Thread by jwilson128 | last post: by
1 post views Thread by =?Utf-8?B?RWl0YW4=?= | last post: by

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.