No dataview item property?

E

Earl

Noting first that I'm coming from VS2003 and VB.Net ...

Using an untyped dataset, I create a dataview. When I try to use the Item
property, "Item" does not appear on the Intellisense dropdown and I also get
the build error "'System.Data.DataView' does not containt a definition for
'Item'." The documentation for VS2005 does show Item as a property of a
dataview -- can anyone see the issue?

DataView dvContacts = new DataView(ds.Tables["dtContacts"]);
int intCounter = dvContacts.Count;

for (intCounter = 0; intCounter < -1; intCounter++)
{
intContactID =
System.Convert.ToInt32(dvContacts.Item(intCounter).Column["ContactID"]);
....
}
 
S

Steven Nagy

instead of:
dvContacts.Item(intCounter).Column["ContactID"]);

Try:
dvContacts[intCounter]["ContactID"];
 
E

Earl

Thanks Steven. That does work. Any reason why the more verbose Item property
shown in the documentation does not work also?
 
S

Steven Nagy

Not 100% sure really.. Does it say that the Item property exists in the
C# syntax?
The default accessor for the collection in VB can use the ITEM
property, but it can also avoid it in the same way C# does (tho with
parenthesis, not square brackets of course).
Not sure what the design reasons for this are... but it just is. No
ITEM property in C#. Remember that and you can't go wrong. :)
 
E

Earl

Yes, it says the Item property exists in C#, but I think I had the syntax
incorrect and I didn't see an example of usage. In any event, if it is
unnecessary, so much the better.
 
S

Steven Nagy

C# is all about shortcuts. :)

Yes, it says the Item property exists in C#, but I think I had the syntax
incorrect and I didn't see an example of usage. In any event, if it is
unnecessary, so much the better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top