By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Datagrid scrolling onCurrentCellChanged

P: n/a
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.Mo usePosition.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.DataSourc e),CurrencyManager)
'Loops through all columns
Dim i As Integer
For i = 0 To dgrid.VisibleColumnCount - 1
d = CType(ds.GridColumnStyles(i),DataGridEnableTextBox Column)
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

--------------------------------
From: John Bayly

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>D8xzNOKwpEO8bmMSWisn/Q==</Id>
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"John Bayly via .NET 247" <an*******@dotnet247.com> wrote in message
news:e0****************@TK2MSFTNGP10.phx.gbl...
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

--------------------------------
From: John Bayly

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>D8xzNOKwpEO8bmMSWisn/Q==</Id>
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.