Override add on bindinglist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ste

    Override add on bindinglist

    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<myc ustomobjectbut 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.
  • Pavel Minaev

    #2
    Re: Override add on bindinglist

    On Jul 22, 6:24 pm, Ste <sceru...@svilu pso.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<myc ustomobjectbut 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.

    Comment

    • Ste

      #3
      Re: Override add on bindinglist

      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...@svilu pso.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<my customobjectbut 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.

      Comment

      Working...