What does this error mean when I try to add rows to a datagrid?

howester77

Active member
Joined
Aug 5, 2005
Messages
38
Programming Experience
5-10
When I create a new row, set the Column value to something, and debug the application, VB.NET 2005 skips over the line in which the value of a column is set. For example,

Dim data As DataRow
data = DataT1.NewRow

(the following line is what VB skips)
data("Time") = strTime

So, I created a breakpoint at that line and this is what came up.

"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user"

what does that mean?
 
It means VB isnt as good as C#.. in C# it fires the indexes in for us and looks at the results. :D:D

If you dont want to power-program in C#, you can always do as VB says:

In order to look at the contents of something that is indexed, you must provide the index


i.e. for a database sql command with parameterized sql, the .Parameters collection is a colelction of parameters. If you debug .Parameters you will only see "must provide index.."

If you go to the immediate window and type:
?myDbCommand.Parameters(2)

(the number in red is the index)

Then you'll see everything you want to know. And if it isnt the third item you want, you can pass 3, 5, "myParameterName" or whatever else it needs as an index


In order to look at the contents of an indexed collection, you must provide the index that VB is to interrogate -- seems straightforward enough to me!

Ps, you were pointing at the word "data" which refers to a data row, which has a default property of .Items
because you were effectively pointing to a line of code that said:

data.Items

You were pointing to a collection (items)


If you selected(highlighted) the whole thing:
data("Time")

and then pointed to the selection, then you;d have seen what you wanted
 
cjard said:
Ps, you were pointing at the word "data" which refers to a data row, which has a default property of .Items
because you were effectively pointing to a line of code that said:

data.Items

You were pointing to a collection (items)

When you point to the word DATA, vb thinks "hmm, what is this DATA?"
It goes and finds out that it is a DataRow
A DataRow has a default property of its items. That means if you write data(something) vb will assume you are referring to the .Items proeprty
.Items is a collection.
when you point to a collection in VB, you see a message to the effect of "in order to evaluate the contents of a collection, you must specify the index you want me to look at"
this is what is happening when you point at "data"

cjard said:
If you selected(highlighted) the whole thing:
data("Time")

and then pointed to the selection, then you;d have seen what you wanted
put the breakpoint on the line
point the mouse to just before the letter D in data
press the left mouse button down
move the mouse right, until the cursor goes past the )
release the mouse button
now, you should see the data("Time") is highlighted witha blue background and white text
now move the mouse away for a second
now point to the blue selection highlight
 
thank you for telling me how to highlight something, though that was not what I was asking.

can you show me a sample code? I understand I was pointing to a collection so how do I fix it?
The follow do not work even though I have specified the index
data.item(0) = strTime
data(0) = strTime
data("Time") = strTime

ps - your way of finding the information can be obtained another way...look at the window at the bottom > it will tell you the exact same thing.
 
Do you have any columns in this DataRow? Specifically the "Time" column. If you don't have the column then VB cannot associate a value to an object that does not exist.
 
ps - your way of finding the information can be obtained another way...look at the window at the bottom > it will tell you the exact same thing.

Thanks for pointing out the use of the Immediate window - it was something I was already aware of, and compared to interrogating the variables using point and click, it is extremely time consuming.. which is why I didnt recommend it in this case
 
Do you have any columns in this DataRow? Specifically the "Time" column. If you don't have the column then VB cannot associate a value to an object that does not exist.

"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user" is NOT an exception thrown when the user supplies a key that doesnt exist. The exception you are referring to is "The given key was not found in the dictionary" or "Column x does not belong to table y"

"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user" is a message returned by the debugger when attempting to evaluate the contents of a collection purely from the collection name. VB cannot do this. You msut explicitly tell VB which collection item you want to interrogate. Without that, you will only see the interrogator tooltip provide you with known properties about the collection, such as the count.


I dont know what else I can say to further beat this topic to death. The message is not a coding error, or a runtime error, its a simple user fault based on an incorrect assumption of how the debugger works. Here's a picture to hopefully show what I mean:
 

Attachments

  • Image1.png
    Image1.png
    38.6 KB · Views: 81
Back
Top