Results 1 to 5 of 5

Thread: Protected, Shadow, etc.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    Protected, Shadow, etc.

    Hi all,

    I found this snippet from syncfusion.com to programmatically scroll the datagrid to a particular row

    VB Code:
    1. Public Class MyDataGrid
    2.        Inherits DataGrid
    3.            Sub ScrollToRow(ByVal row As Integer)
    4.                 If Not Me.DataSource Is Nothing Then
    5.                      Me.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
    6.                 End If
    7.            End Sub
    8.       End Class

    How can I incorporate this in my code. I have a form with a datagrid. If I remove public class to just retain the sub block:

    VB Code:
    1. Sub ScrollToRow(ByVal row As Integer)
    2.                 If Not datagrid1.DataSource Is Nothing Then
    3.                      datagrid1.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
    4.                 End If
    5. End Sub

    i get an error:

    D:\vendormst\vendor.vb(263): 'System.Windows.Forms.DataGrid.Protected Overridable Overloads Sub GridVScrolled(sender As Object, se As System.Windows.Forms.ScrollEventArgs)' is not accessible in this context because it is 'Protected'.

    Could somebody help me to understand the concept protected, override, shadow, overloading. I've read a lot of topics about these but couldn't understand these fully.

    Thanks a lot.

  2. #2
    Junior Member
    Join Date
    Nov 2002
    Location
    New York
    Posts
    29
    That is a class that inherits the DataGrid class and adds an additional method called ScrollToRow.

    So, in your code, copy the class definition as it is and then define an object of type MyDataGrid. for example:

    dim dg as MyDataGrid
    dg = New MyDataGrid()
    ...
    here do all the initializations as if you were working with a regular DataGrid

    And when you need you can do:

    dg.ScrollToRow(x)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    kindly clarify

    hi,

    I can't fully understand what you mean. Do you mean I would create a datagrid dynamically?

    What I have currently is a form and a datagrid (datagrid1) created at design. How can I make use of the function ScrollToRow().

    Kindly clarify.

    Thanks a lot.
    Marivic

  4. #4
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    hi
    Don't remove the 'public class' part. I think you should write this
    Public Class MyDataGrid
    Inherits DataGrid
    Sub ScrollToRow(ByVal row As Integer)
    If Not Me.DataSource Is Nothing Then
    Me.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
    End If
    End Sub
    End Class


    and in your form create an object from that

    dim dg as MyDataGrid
    dg = New MyDataGrid()

    so that you can use the 'scrolltorow' method of dg.
    when in doubt, win the trick

  5. #5
    Junior Member
    Join Date
    Nov 2002
    Location
    New York
    Posts
    29

    Re: kindly clarify

    The thing is: whenever you want to create a control that is implemented by the visual environment you can use the designer to do it. When you want to create a "special" control, like the auto scrolling datagrid, you will create a class that inherits the original class and basically have a new control. The new control cannot be used in the designer mode unless you take additional steps:

    1. create the class that inherits the original control
    2. complile the assembly as a DLL
    3. right-click on the toolbar and choose customize
    4. add your DLL there

    Then you will be able to use the designer with your new control. However there are a lot of issues in how to create custom controls and books give whole chapters to this topic.

    In your case I would really create the control dynamically.

    Originally posted by Marivic
    hi,

    I can't fully understand what you mean. Do you mean I would create a datagrid dynamically?

    What I have currently is a form and a datagrid (datagrid1) created at design. How can I make use of the function ScrollToRow().

    Kindly clarify.

    Thanks a lot.
    Marivic

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