469,576 Members | 1,624 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,576 developers. It's quick & easy.

<cannot view indexed property>


Hi,

I have created a collection of a custom class. Everything works fine (can add these items in a combo from within a VB.NET application, for instance), but when looking at the collection from a VB.NET application in the Watch window, I cannot see the items of the collection. The message in the Watch window's "value" says: "<cannot view indexed property>." Below is the code I wrote.

Any idea of what is wrong? Or is the error message "correct"?

Thanks a lot.
Mike


public class Companies : IEnumerable {

ArrayList m_oCompanies = null;

public Companies() { // Nothing is done in the constructor. }
public void Add(Company oCompany) {...}
public Company this[int index] {
get { return (Company)m_oCompanies[index]; }
}

public int Count { ... }

}

public IEnumerator GetEnumerator() { return new CompaniesEnumerator(m_oCompanies); }

// Inner class implements IEnumerator interface:
class CompaniesEnumerator : IEnumerator {

int index;
ArrayList m_oCompanies;

public CompaniesEnumerator(ArrayList oCompanies) { this.m_oCompanies = oCompanies; }

public bool MoveNext() { return (++index < m_oCompanies.Count); }

public object Current {
get {
if (index < m_oCompanies.Count) return m_oCompanies[index];
else
return null; }
}

public void Reset() { ... }
Nov 20 '05 #1
1 3209
Mike,

The watch window cannot view properties that have an indexer. If you need to
see the contents of an indexed property, specify the index as part of the
watch.

e.g.

m_oCompanies.Item(0)

You'll get an exception if the index you specify is out of range.

On a side note, I didn't know you could compile C# code with VB.net ;) (your
source is c#, but your post refers to VB)

HTH,

Trev.
"Mike" <no****@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...

Hi,

I have created a collection of a custom class. Everything works fine (can
add these items in a combo from within a VB.NET application, for instance),
but when looking at the collection from a VB.NET application in the Watch
window, I cannot see the items of the collection. The message in the Watch
window's "value" says: "<cannot view indexed property>." Below is the code I
wrote.

Any idea of what is wrong? Or is the error message "correct"?

Thanks a lot.
Mike


public class Companies : IEnumerable {
ArrayList m_oCompanies = null;

public Companies() { // Nothing is done in the constructor. }
public void Add(Company oCompany) {...}
public Company this[int index] {
get { return (Company)m_oCompanies[index]; }
}
public int Count { ... }
}
public IEnumerator GetEnumerator() { return new
CompaniesEnumerator(m_oCompanies); }
// Inner class implements IEnumerator interface:
class CompaniesEnumerator : IEnumerator {
int index;
ArrayList m_oCompanies;
public CompaniesEnumerator(ArrayList oCompanies) { this.m_oCompanies =
oCompanies; }
public bool MoveNext() { return (++index < m_oCompanies.Count); }
public object Current {
get {
if (index < m_oCompanies.Count) return m_oCompanies[index];
else
return null; }
}
public void Reset() { ... }
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike | last post: by
2 posts views Thread by Jofio | last post: by
reply views Thread by Debajit Adhikary | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.