Items property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

why is it that some collection classes, eg BindingList, but others as well do
not expose their Items property? It is there as a Protected property so why
not make it public?

I can work around this but there must be a design reason for this, what is it?

--guy--
 
guy said:
why is it that some collection classes, eg BindingList, but others
as well do not expose their Items property? It is there as a
Protected property so why not make it public?

I can work around this but there must be a design reason for this,
what is it?


BindingList: "Search found no results"

System.Windows.Forms.BindingsCollection.Item, if you mean that, is public.


Armin
 
Hi Armin,
my thought was that you cant do a

For Each thing as Object in myBindingList.Items

you have to do something like

For i=1 to myBindingList.Count
thing=myBindingList.Item(i)

i just wondered why it was designed this way

cheers

guy
 
sorry Armin i should have made it clear, i am using vb2005, and it is the
System.ComponentModel.BindingList that i am refering to
 
guy said:
sorry Armin i should have made it clear, i am using vb2005, and it
is the System.ComponentModel.BindingList that i am refering to


It's also not found in VB 2005.

.....later....

I had to enter "bindglist(of t)" in order to find it. What a new nonsense.
:-((((( When I press F1 then, the topic is not found. I love it.

Sorry, I can not help you.


Armin
 
guy,
BindingList does not expose an Items collection as BindingList itself is the
"items" collection.

Instead of:

| For Each thing as Object in myBindingList.Items

Use:

For Each thing as Object in myBindingList



FWIW: If you have a type that has an "Items" collection that suggests that
you have a type that *has* a collection. Classes such as BindingList (that
have a Count & Item properties, GetEnumerator method) *are* a collection.
Generally For Each requires that the type implement IEnumerable or
IEnumerable(Of T). However For Each can operate on types that have a
GetEnumerator method without implementing either interface... Unfortunately
I don't have the link handy on the specifics of what For Each looks for...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi Armin,
| my thought was that you cant do a
|
| For Each thing as Object in myBindingList.Items
|
| you have to do something like
|
| For i=1 to myBindingList.Count
| thing=myBindingList.Item(i)
|
| i just wondered why it was designed this way
|
| cheers
|
| guy
|
| "Armin Zingler" wrote:
|
| > > why is it that some collection classes, eg BindingList, but others
| > > as well do not expose their Items property? It is there as a
| > > Protected property so why not make it public?
| > >
| > > I can work around this but there must be a design reason for this,
| > > what is it?
| >
| >
| > BindingList: "Search found no results"
| >
| > System.Windows.Forms.BindingsCollection.Item, if you mean that, is
public.
| >
| >
| > Armin
| >
 
Back
Top