Re: Object Reference to MyBase

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Dennis (Dennis_at_discussions.microsoft.com)
Date: 10/24/04


Date: Sun, 24 Oct 2004 08:45:02 -0700

Imran, thank you very much for your time in answering my question. What I'm
trying to do is set the rowheights in class that inheirits the datagrid
control. The following works for the Datagrid class but doesn't work for
inheirited classes where dg is datagrid object (or my class that inheirits
the datagrid class). The "get_DataGridRows" is a private method, I'm told,
in the DataGrid control.

Dim mi As MethodInfo = dg.GetType().GetMethod("get_DataGridRows", _
BindingFlags.FlattenHierarchy Or BindingFlags.IgnoreCase Or _
BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or _
BindingFlags.Static)

Dim dgra As System.Array = CType(mi.Invoke(Me.dg, Nothing), System.Array)

I understand what you are saying about the private methods of the class
that's being inheirited not accessable but there must be some way to get at
the rowobject collection of the datagrid base class. I'll play around with
your reflection example some and see what I can do. Thanks again.

"Imran Koradia" wrote:

> Dennis,
>
> I don't think my previous comment would have answered your question
> completely. As I mentioned, the MyBase keyword refers to the current
> instance of the derived class. As far as private methods (or properties,
> etc) go, when a class derives from a base class, the private methods are not
> inherited and so there is nothing like accessing the private methods of the
> base class! When you look at a derived class, there's just one class - the
> derived class - that has its own members and members inherited from the base
> class. Since private members are not inherited, the derived class simply
> doesn't have them and is completely unaware of them. So there's no question
> about executing a private method of the base class in the context of the
> derived class since that doesn't make sense at all, IMO.
>
> I hope that clears things up a bit..
> Imran.
>
> "Dennis" <Dennis@discussions.microsoft.com> wrote in message
> news:2CD32FB8-DCC0-4160-AAB8-AE0134E76044@microsoft.com...
> > The base class I am inheriting is a VB.Net control and I have no control
> over
> > the scope of it's methods. Do you have any idea how I can use reflection
> to
> > get at the method of the base class? It's not an exposed method that you
> can
> > call using MyBase.baseclassmethod.
> >
> > "Imran Koradia" wrote:
> >
> > > Can you make the base class method protected? That way only the derived
> > > classes can access the method - in a way its 'private' to the base class
> and
> > > all classes that derive from it. Then you can simply call
> > > MyBase.BaseClassMethod or infact you can also call Me.BaseClassMethod
> since
> > > the derived class inherits this method.
> > >
> > > Apart from that, AFAIK, there's no direct way to access the private
> methods
> > > of the base class. You would have to resort to using Reflection to
> access
> > > the method.
> > >
> > > hope that helps..
> > > Imran.
> > >
> > > "Dennis" <Dennis@discussions.microsoft.com> wrote in message
> > > news:C82453F3-F85D-47CC-9C5C-AEA9AB32DAC3@microsoft.com...
> > > > When a class (myownclass) inheirits another class, how can I get an
> object
> > > > reference to the underlyng MyBase class instance from within
> myownclass.
> > > > The
> > > > base class has a method that I want to utilize in myownclass but the
> > > > method
> > > > is private and can't be inheirited. I need to utilize that base
> class
> > > > method.
> > > >
> > > > --
> > > > Dennis in Houston
> > >
> > >
> > >
>
>
>



Relevant Pages

  • Re: Object Reference to MyBase
    ... > trying to do is set the rowheights in class that inheirits the datagrid ... > the rowobject collection of the datagrid base class. ... >> etc) go, when a class derives from a base class, the private methods are ... Since private members are not inherited, the derived class simply ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Class Inherits Question
    ... Remember Inherits is about adding or specializing functionality of a base ... It is not about REMOVING functionality of a base class. ... However it sounds like you want to say: I don't have a DataGrid at all, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Reference base class parameter, is this possible...
    ... The parameters are reference because I'm populating a DataGrid via a method. ... The reason I'm in this position is I wanted to make the method more generic ... that are accessed by the method are in the base class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reference base class parameter, is this possible...
    ... > The datagrid is bound to data, and can have the visibility property set to ... > work because I'd be left with a copy of the datagrid object, ... > properties that are accessed by the method are in the base class (or its ... >> reference, see ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: DataGrid Column By Text
    ... Here is some code that shows how the grid is built from the ground up, ... Put a datagrid on a form. ... Then add a Datagrid CurrentCellChanged event handler: ... This declaration is made of the base class, ...
    (microsoft.public.dotnet.languages.vb)