StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Need help decifering a concept...Expand / Collapse
Author
Message
Posted 08/11/2006 7:19:55 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 07/09/2008 2:20:16 PM
Posts: 436, Visits: 944
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.

Thanks for the help.
Post #2156
Posted 08/11/2006 3:47:18 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 09/26/2008 8:30:36 AM
Posts: 2,685, Visits: 1,886
Hi Mike,

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()


www.bungie.net
Post #2162
Posted 08/11/2006 3:48:43 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 09/26/2008 8:30:36 AM
Posts: 2,685, Visits: 1,886
In CSharp, the indexer properties cannot use the property name, but instead, they use the square brackets, so it looks like this instead:

this.cboDivisions.Properties.GetDataSourceRowByKeyValue(Me.cboDivisions.EditValue)["LocationID"].ToString();


www.bungie.net
Post #2163
Posted 08/11/2006 3:50:04 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 07/09/2008 2:20:16 PM
Posts: 436, Visits: 944
Thanks Ben! Good stuff!
Post #2165
Posted 08/11/2006 3:52:09 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 09/26/2008 8:30:36 AM
Posts: 2,685, Visits: 1,886
No problem


www.bungie.net
Post #2166
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 5:38am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.047. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.