Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How does a control refer to itself?
Message
De
27/03/2008 04:27:40
 
 
À
26/03/2008 17:55:42
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01305989
Message ID:
01306076
Vues:
4
>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.

Where is this code? In a Form?
In that case since the mmDataGridView1_CellContentClick() method belongs to the Form then 'this' refers to the form. In short 'this' always refers to the class in which it is contained (except in extension methods). I don't see how this (no pun intended) differs from VFP behaviour.
BTW the 'This.' isn't needed unless there can be ambiquity.
HTH,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform