|
-
Nov 11th, 2002, 04:40 AM
#1
Thread Starter
Addicted Member
Protected, Shadow, etc.
Hi all,
I found this snippet from syncfusion.com to programmatically scroll the datagrid to a particular row
VB Code:
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
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:
Sub ScrollToRow(ByVal row As Integer)
If Not datagrid1.DataSource Is Nothing Then
datagrid1.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
End If
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.
-
Nov 11th, 2002, 03:32 PM
#2
Junior Member
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)
-
Nov 11th, 2002, 08:50 PM
#3
Thread Starter
Addicted Member
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
-
Nov 12th, 2002, 03:33 AM
#4
Lively Member
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
-
Nov 12th, 2002, 08:57 AM
#5
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|