J
John Bayly via .NET 247
I'm working on an inherited Datagrid class that includes afunction called onMouseMove to paint the row under the cursor tomake reading easier for users.
To paint the row, the function sets the current cell to by:
'Get Screen Coorinate of Mouse Cursor
Dim p As Point = New Point(dgrid.Parent.MousePosition.X,dgrid.Parent.MousePosition.Y)
'Convert Screen Coordinates to Local Coordinates
Dim pC As Point = dgrid.PointToClient(p)
'Runs Hit Test on Datagrid
Dim ht As DataGrid.HitTestInfo = dgrid.HitTest(pC)
'Check if Mouse is over Cell
If ht.Type = DataGrid.HitTestType.Cell Then
'Get current row and column
Dim r As Integer = ht.Row
Dim c As Integer = ht.Column
'Set Current Cell to Cell under mouse cursor
dgrid.CurrentCell = New DataGridCell(r, c)
'Gets Information for passing to paint method
Dim ds As DataGridTableStyle = dgrid.TableStyles(0)
Dim d As DataGridEnableTextBoxColumn
Dim curr As CurrencyManager
Dim g As Graphics = dgrid.CreateGraphics
Dim rect As Rectangle
Dim fBrush As SolidBrush = NewSolidBrush(Color.Gold)
Dim bBrush As SolidBrush = NewSolidBrush(Color.FromArgb(51, 51, 51))
curr =CType(dgrid.Parent.BindingContext(dgrid.DataSource),CurrencyManager)
'Loops through all columns
Dim i As Integer
For i = 0 To dgrid.VisibleColumnCount - 1
d = CType(ds.GridColumnStyles(i),DataGridEnableTextBoxColumn)
If d.Width > 0 Then
rect = dgrid.GetCellBounds(r, i)
d.PaintCol(g, rect, curr, r, bBrush, fBrush,False)
End If
Next
End If
DataGridEnableTextBoxColumn is a class inherited fromDataGridTextBoxColumn
The problem I am having is that when the user moves the mouseover the last visible row in the datagrid (example row=7), itcalls the function, and when the currentcell is changed, it willautomatically scroll down by 1 row. The mouse cursor stillremains in the original positions (now over row=8). If the mouseis moved again, it will scroll down another row. What I need todo is stop the datagrid from scrolling automatically when thelast currentcell is set to the last visible row.
Does anybody have any idea how to stop this, my users are gettingseriously sick of uncontrolled scrolling when trying to viewdata
To paint the row, the function sets the current cell to by:
'Get Screen Coorinate of Mouse Cursor
Dim p As Point = New Point(dgrid.Parent.MousePosition.X,dgrid.Parent.MousePosition.Y)
'Convert Screen Coordinates to Local Coordinates
Dim pC As Point = dgrid.PointToClient(p)
'Runs Hit Test on Datagrid
Dim ht As DataGrid.HitTestInfo = dgrid.HitTest(pC)
'Check if Mouse is over Cell
If ht.Type = DataGrid.HitTestType.Cell Then
'Get current row and column
Dim r As Integer = ht.Row
Dim c As Integer = ht.Column
'Set Current Cell to Cell under mouse cursor
dgrid.CurrentCell = New DataGridCell(r, c)
'Gets Information for passing to paint method
Dim ds As DataGridTableStyle = dgrid.TableStyles(0)
Dim d As DataGridEnableTextBoxColumn
Dim curr As CurrencyManager
Dim g As Graphics = dgrid.CreateGraphics
Dim rect As Rectangle
Dim fBrush As SolidBrush = NewSolidBrush(Color.Gold)
Dim bBrush As SolidBrush = NewSolidBrush(Color.FromArgb(51, 51, 51))
curr =CType(dgrid.Parent.BindingContext(dgrid.DataSource),CurrencyManager)
'Loops through all columns
Dim i As Integer
For i = 0 To dgrid.VisibleColumnCount - 1
d = CType(ds.GridColumnStyles(i),DataGridEnableTextBoxColumn)
If d.Width > 0 Then
rect = dgrid.GetCellBounds(r, i)
d.PaintCol(g, rect, curr, r, bBrush, fBrush,False)
End If
Next
End If
DataGridEnableTextBoxColumn is a class inherited fromDataGridTextBoxColumn
The problem I am having is that when the user moves the mouseover the last visible row in the datagrid (example row=7), itcalls the function, and when the currentcell is changed, it willautomatically scroll down by 1 row. The mouse cursor stillremains in the original positions (now over row=8). If the mouseis moved again, it will scroll down another row. What I need todo is stop the datagrid from scrolling automatically when thelast currentcell is set to the last visible row.
Does anybody have any idea how to stop this, my users are gettingseriously sick of uncontrolled scrolling when trying to viewdata