Datagrid scrolling onCurrentCellChanged

  • Thread starter John Bayly via .NET 247
  • Start date
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
 
J

Jens Blom

Hi
Try this
=======================
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
Dim foo As Web.UI.WebControls.DataGridItem = e.Item
foo.Attributes.Add("onmouseover", "bgColor='#345622'")
foo.Attributes.Add("onmouseout", "bgColor=''")
End Sub
=======================

Let me know if its was what ur looking 4
/Jens


I'm working on an inherited Datagrid class that includes a function called
onMouseMove to paint the row under the cursor to make 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 = New SolidBrush(Color.Gold)
Dim bBrush As SolidBrush = New SolidBrush(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 from DataGridTextBoxColumn

The problem I am having is that when the user moves the mouse over the last
visible row in the datagrid (example row=7), it calls the function, and when
the currentcell is changed, it will automatically scroll down by 1 row. The
mouse cursor still remains in the original positions (now over row=8). If
the mouse is moved again, it will scroll down another row. What I need to do
is stop the datagrid from scrolling automatically when the last currentcell
is set to the last visible row.

Does anybody have any idea how to stop this, my users are getting seriously
sick of uncontrolled scrolling when trying to view data
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top