CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    'hide' DataBind method

    Hi all,

    I'm creating a custom control. To show the correct data in this control, I need to set several properties before calling the DataBind method. To prevent that any properties are forgotten, or that someone else doesn't know what properties to set, I want to pass all this information to the databind method.
    Code:
    public void DataBind(int value, string something, double anotherValue) {
      //..
    }
    This approach works fine so far, but code completion still shows the original DataBind (+1 overload). I tried to override this method, and make it private, but this results in a compiler error ('virtual or abstract members cannot be private').

    Is this possible?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: 'hide' DataBind method

    As quoted from here :

    http://www.dotnetperls.com/private-virtual-methods

    Private virtual methods make no sense. The reason private virtual methods are nonsensical is because whenever a private method is invoked, the type has already been entered—you can always define custom private methods on a type and if you are already inside the type, you can simply call a regular instance private method. Further, instance and static methods are faster to invoke than interface and virtual methods, so there is a performance advantage to not using a private virtual method.
    Perhaps if we have a better understanding of what your class looks like, we could possibly assist further

  3. #3
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: 'hide' DataBind method

    My custom control is simply displaying some data which I select in the database. But to select the data, I need several paramaters. So I could declare these parameters in public properties, and make sure these properties are set before calling the DataBind method. But if multiple paramaters are required, it's easy to forget one. Or what if some of them are optional parameters? Using the properties, it's hard to see what is required and what not.

    So if there paramaters are set using parameters in the DataBind method, it's impossible to forget to set them correctly, and you can see inmediately which are required and which are optional.

    I hope I clarified myself now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured