Scrolling DataGrid Programatically
'The DataGrid has a protected member named GridVScrolled that can be used to scroll the grid. We can derive from DataGrid and add a SendToRow method.
Steps :
'/** Add New Project --> Class Library --> MyDataGrid.vb (Name of Class Library) '/** 'SendToRow' is a UserDefine Method. '/** 'GridVScrolled' is a Protected Member. '/*** Build --> Build Solution (DLL file created the Path. Ex: 'D:\WDataGrid\bin\WDataGrid.dll'.)
'/** 'System.Windows.Forms' Namespace for accessing the ScrollEventArgs Class, ScrollEventType Enum.
Imports System.Windows.Forms
Public Class MyDataGrid Inherits System.Windows.Forms.DataGrid Sub SendToRow(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
'/** Open a New Windows Application and follow the below steps. '/** Right Click on ToolBox --> (Select)Customize ToolBox --> (Select) .Net Framework Components (Tab) '/** (Click) Browse (Button) --> Locate the File Path 'D:\WDataGrid\bin\WDataGrid.dll'. '/** (Click) Open (Button) --> OK. '/** Now, One New component added on your ToolBox named 'MyDataGrid'. '/** You cane Drag and Drop it on your Form.
Imports System.Data.SqlClient
Public Class Form1 Inherits System.Windows.Forms.Form Private _CON As SqlConnection Private _ADA As SqlDataAdapter Private _DSET As New DataSet()
Private Sub Form1_Load(...) Handles MyBase.Load _CON = New SqlConnection("Server=;DataBase=;uid=;pwd=") _ADA = New SqlDataAdapter("Select * from TableName", _CON) _CON.Open() _ADA.Fill(_DSET) _CON.Close() MyDataGrid1.DataSource = _DSET.Tables(0) End Sub
Private Sub Button1_Click(...) Handles Button1.Click MyDataGrid1.SendToRow(RowIndex) MyDataGrid1.Select(RowIndex) End Sub
'/** 'MyDataGrid1.SendToRow' send one value as 5, Grid scroll to 5th Row. '/** The current row always @ first row.
'/** 'MyDataGrid1.Select' - Highlighted the row which you have given the 'RowIndex'.
Happy Coding
|
No responses found. Be the first to respond and make money from revenue sharing program.
|