Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help decifering a concept...

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
Can someone help me decifer this line of code? I saw it somewhere and have used it a couple of times but I'm not sure what the concept is called or why it works.

Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue)("LocationID").ToString

If this piece of code were to take up two lines this is what it would look like this

Dim row As DataRowView = Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue)
Messagebox.Show(row("LocationID").ToString)

I'm referring to the way I can butt the set of parenthesis together and I've highlighted this in green and red.

Thanks for the help.
 
Judging by the code, the GetDataSourceRowByKeyValue() function must return a collection.
 
Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue) gives you the DataRowView associated with the value selected in your cboDivision combo box. Putting the ("LocationID") after it returns you the LocationID field out of that DataRowView.
 
Thanks guys. I just wasnt sure if there was a name for this concept.
 
Here's a response I got on another board just thought it might help somebody else:

The reason you can butt the parenthasis together is because of the way the properties work. It is the same concept as that of chaining together a bunch of dots, like this:

Me.TextBox1.Text

The first dot tells the "Me" variable that we are accessing one of its properties. The second dot tells the TextBox that we are accessing one of its properties.

Now, there are special properties called "indexers." An indexer is a "default" property that allows you to leave off the property name because it is understood. So, When you execute the GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue) method, it returns an instance to a DataRowView. If you were to put a dot at the end of those parenthasis, you would be telling the DataRowView that you want to access it's properties. So, you could do this: Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue).Row which would return the DataRow wrapped by the DataRowView. So, we combine this with the indexer property of the DataRowView item, which accepts a column name and returns the value within the field. So, since the property is the indexer (its the "Item" propery), you can leave off the .PropetyName because it's understood. So, the parenthasis are butted together because the ".Item" is understood, and therefore, left off.

Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue)("LocationID").ToString()

Me.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue).Item("LocationID").ToString()
 
We could have told you that ;) heh.

The concept is just an inline function call. If MyObject.GetThing returns a string, you can treat "MyObject.GetThing" as if it where a string. Like MyObject.GetThing.TrimEnd.

Likewhys, if MyObject.GetThings returns an array, you can treat MyObject.GetThings as if it where an array, like MyObject.GetThings.Count, or in this case MyObject.GetThings(0).

Now, if element 0 of the MyObject.GetThings array is a collection, you can treat MyObject.GetThings(0) as a collection. Which means that MyOjbect.GetThings(0)("Identifier") will get the "Identifier" item from the MyObject.GetThings(0) collection.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top