datagrid sort cursor

T

thomasp

I have a datagridview that allows the user to sort the column by clicking on
the header of the column the user wishes to sort. I did not code this, it
had the ability when the datagrid was populated. My question is how can I
change the cursor to an hourglass when the user clicks the header and change
it back to the default once the sort is accomplished. The database is large
and the sort takes a few seconds. Need something to show the user the
program is working so the user does not continue to click the header.

Thanks,

Thomas
 
K

Ken Tucker [MVP]

Hi,

In the mousedown event on the datagrid check and see if the use clicked on
the column header and change the cursor.

Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Click

Dim pt As Point = DataGrid1.PointToClient(Cursor.Position)

Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.ColumnHeader Then

' Change cursor here

End If

End Sub

Here is how to know when the grid was sorted. Change the cursor back after
it was sorted.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=7bd8c12a-b448-4b16-8c80-7a5dcc005f84

Ken
-----------------------------
I have a datagridview that allows the user to sort the column by clicking on
the header of the column the user wishes to sort. I did not code this, it
had the ability when the datagrid was populated. My question is how can I
change the cursor to an hourglass when the user clicks the header and change
it back to the default once the sort is accomplished. The database is large
and the sort takes a few seconds. Need something to show the user the
program is working so the user does not continue to click the header.

Thanks,

Thomas
 
T

thomasp

I failed to mention I am using VB2005. I changed your code a little to work
in 05, but I can't find a listchanged event to use to know when to go back
to the default cursor.

Do you have a suggestion for that?

Thanks,

Thomas

Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown

Dim myHitTest As System.Windows.Forms.DataGridView.HitTestInfo
' Use the DataGrid control's HitTest method with the x and y properties.
myHitTest = DataGridView1.HitTest(e.X, e.Y)

If myHitTest.Type = DataGridViewHitTestType.ColumnHeader Then
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
End If


End Sub
 

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