Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How does a control refer to itself?
Message
From
26/03/2008 20:49:15
 
 
To
26/03/2008 17:55:42
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01305989
Message ID:
01306044
Views:
4
Just to build on what Einar said, as you've noticed, the method you posted doesn't natively know what control was clicked to get there. The method only knows it belongs to the form. That's why "this" refers to the form.

But the parameters that are passed to this method do contain that information, specifically the sender parameter. But the standard for these types of methods is to accept an object paramter. But "object" does not know what methods/properties belong to the actual type passed in (sender).

That's why in Einar's example you have to "(mmDataGridView)sender)". You have to tell the method in detail what type of object was passed in so you can reference the methods/properties of that object.

>If I want to refer to a method or property of an object's own structure, how can I do that without having to use its own name to drill down to it?
>
>i.e.
>
>
>        private void mmDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
>        {
>            string CustNo = this.mmDataGridView1.GetCurrentRowPK();
>
>        }
>
>
>You see that I am having to use "this.mmDataGridView1" within the method just to refer to method with the same object.
>
>In Foxpro we coud say "this.method_name()" or "this.property_name" to access a method or property within a control's own structure, but in C#, "this" means the entire parent class, not the current object who's method code is firing.
>
>This is hard to explain, so I hope the question has made sense.

(On an infant's shirt): Already smarter than Bush
Previous
Reply
Map
View

Click here to load this message in the networking platform