Some Quick Questions

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

    #1

    Some Quick Questions

    A few quick questions if possible.

    1 - If I have a "List<..myL ist" and set it as a datasouce for say
    ListBox1, then change items in "myList" is the correct/only way to
    update the ListBox with the following?

    ListBox1.DataSo urce = null;
    ListBox1.DataSo urce = myList;

    2 - BindingList<... is the same as List<...except when it is set as
    a datasource then it auto updates the ListBox on changes (One Way
    Only) basically? Should I pretty much always be using
    BindingList<... if its being used as a datasouce and items are
    changing? Is there an easy way to search MSDN for all Data Storage
    Types that AutoUpdate when bound to a DataSource or is this basically
    the only one?

    3 - When Using the foreach enumeration I always seem to run into
    "collection can't change" exception, and then forced to copy the
    elements I want using the "CopyTo(..) " (of if I'm lucky and the
    collection has it - ToArray()), or just use the simple
    "for(...)" (Which is what I usally do since I don't like using up the
    extra memory with the copy/toarray). Basically wondering if I am
    doing this the right way or is there something else that the
    getEnumeration makers put in place for me in these situations.


    Thanks. I know these are probably really basic questions but I run
    into them so often and just want to make sure I'm doing it the best
    way I can.
  • Marc Gravell

    #2
    Re: Some Quick Questions

    1: Well, if there is a BindingSource in the mix you could call
    ResetBindings() , but otherwise yes

    2: Anything that provides an IBindingList implementation with support
    for notifications (ListChanged) will suffice. BindingList<T(f or
    classes) and DataView (for DataTables) are the most common two, but
    you can write your own from scratch etc (if you feel so inclined). You
    can also subclass BindingList<Tto fill in the blanks (sorting
    support, etc).

    3: What are you trying to do to the collection? List<T(but not
    BindingList<T>) offers various delegate-based methods for removing
    multiple items etc - but it is right: if the list contents change, the
    enumerator will break. A standard for(int i ...) will suffice - but
    again, it depends on what you want to do.

    Marc

    Comment

    • Marc Gravell

      #3
      Re: Some Quick Questions

      Is there an easy way to search MSDN for all Data Storage
      Types that AutoUpdate when bound to a DataSource or is this basically
      the only one?
      Well, the hard part is knowing that IBindingList is responsible for
      list updates... MSDN used to offer a "things that derive from this",
      but not any more - so to explain how I (a few moments ago) checked
      this: I fired up the free but excellent "Lutz Roeder's .NET
      Reflector", searched for IBindingList and expanded Derived Types. This
      revealed:

      System.Componen tModel.BindingL ist<T>
      System.Componen tModel.IBinding ListView
      System.Data.Dat aView
      System.Data.Rel atedView
      System.Windows. Forms.BindingSo urce
      System.Data.Dat aViewManager

      So the only other thing (in the standard libraries) that offers this
      is BindingSource, which is actually just an intermediary for working
      with a concrete implementation (like BindingList<Tor DataView).

      Marc


      Comment

      • Marc Gravell

        #4
        Re: Some Quick Questions

        I fired up the free but excellent "Lutz Roeder's .NET Reflector"
        Rather embarrasingly, I've just noticed that you can also get this
        from the Object Browser in Visual Studio... and as such is probably a
        better option for occasional use.

        Marc

        Comment

        • NvrBst

          #5
          Re: Some Quick Questions

          On Jan 15, 2:31 pm, Marc Gravell <marc.grav...@g mail.comwrote:
          I fired up the free but excellent "Lutz Roeder's .NET Reflector"
          >
          Rather embarrasingly, I've just noticed that you can also get this
          from the Object Browser in Visual Studio... and as such is probably a
          better option for occasional use.
          >
          Marc
          Thank you for the replys, they were helpful.

          NB

          Comment

          Working...