Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Some Quick Questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NvrBst - 15 Jan 2008 22:05 GMT
A few quick questions if possible.

1 - If I have a "List<..> myList" 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.DataSource = null;
ListBox1.DataSource = 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 - 15 Jan 2008 22:20 GMT
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> (for
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<T> to 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
Marc Gravell - 15 Jan 2008 22:28 GMT
>  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.ComponentModel.BindingList<T>
System.ComponentModel.IBindingListView
    System.Data.DataView
        System.Data.RelatedView
    System.Windows.Forms.BindingSource
System.Data.DataViewManager

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<T> or DataView).

Marc
Marc Gravell - 15 Jan 2008 22:31 GMT
> 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
NvrBst - 15 Jan 2008 23:00 GMT
> > I fired up the free but excellent "Lutz Roeder's .NET Reflector"
>
[quoted text clipped - 3 lines]
>
> Marc

Thank you for the replys, they were helpful.

NB

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.