Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom DataGridColumn Cursor

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
I'm working a custom datagridcolumn for my app.

It shows 6 16x16 images side by side that act like buttons when clicked (visually they don't change however). The buttons can be disabled simply by the value of the cell ("101010" - every other one is enabled).

The images show up just fine in my datagrid, and I've got the program to send Click events (6 different events with row number as parameter) for the different buttons.

I would like the cursor to change to the Hand when over an enabled button.

Right now I just want the cursor to change - whether its over an enabled button or not I can add that later (that's easy).

I've currently got the MouseMove being trapped by the column and correctly identifying whether it's in the cell or not and then the following:

Code:
            rect = dg.GetCellBounds(hti.Row, hti.Column)
            Dim pointx As Integer = e.X - rect.X
            Select Case pointx
                Case 0 To 16
                    Cursor.Current = Cursors.Hand
                Case 16 To (2 * 16)
                    Cursor.Current = Cursors.Hand
                Case (2 * 16) To (3 * 16)
                    Cursor.Current = Cursors.Hand
                Case (3 * 16) To (4 * 16)
                    Cursor.Current = Cursors.Hand
                Case (4 * 16) To (5 * 16)
                    Cursor.Current = Cursors.Hand
                Case Is > (5 * 16)
                    Cursor.Current = Cursors.Hand
                Case Else
                    Cursor.Current = Cursors.Default
            End Select

What's weird is that the Cursor.Current = Cursors.Hand does run when over the correct button - but my cursor doesn't change.

Any ideas?
 
Problem with MouseHover is that it only passes as arguements the Sender As Object, and e As System.EventArgs.

I need the mouse position within the DataColumn thus MouseMove which passes e As MouseEventArgs.

Also I can't say it's really a control - but a column for a datagrid as it's inheriting DataGridTextBoxColumn - I suppose if you really want to say it it's a control for a control :)
 
can you have 2 cursors? You can hide the default one and show the hand one? Just and idea :)
 
You know - I don't know. I doubt it - but I'll look into it.
 
Ah but both of those examples are using the Cursor.Current = <something> assigment just as I am except they are using custom cursors (msdn one shows it being assigned to the form "Me.Cursor").
 
well you could try
If else statement
and hide the cursor if it is default and show the hand cursor right?
 
Well the If else doesn't work as you can't do:
If Cursor.Current = Cursors.Default Then
So I changed the = to Is. It compiled and ran, but when it got to that point (breakpoint set on that line) it didn't run the code in the If statement like it was false.

The code below was in the if statement:
Cursor.Hide() 'hides the cursor
Cursor.Current = Cursors.Hand 'sets the cursor to Hand
Cursor.Show() 'Shows the cursor

It is essentially what I have running now, but without the Hide/Show statements and.
 
Well the If statement works.

I used:

If Cursor.Current.Equals(Cursors.Default) Then
Cursor.Hide()
Cursor.Current = Cursors.Hand()
Cursor.Show()
End If

Commenting out various parts of the code I found Cursor.Hide() worked, as did Cursor.Show(). But the assignment of the Cursors.Hand() is not working for some reason.
 
why dont you instantiate a new cursor and set it to cursor.hand?
Or use the cursor library that i showe you previously now that we have the show and hide working:)
 
That cursor library from vbCity is for custom cursors - I'm just trying to use a standard Windows cursor, the process of changing the cursor is the same there as what I'm tyring to do - they are just pulling their cursor from an array of cursors created from files.

Public customCursors(NUM_OF_CURSORS) As Cursor
Cursor.Current = customCursors(2)
 
Oh and instantiation didn't work either:

Cursor.Hide()
Dim q As New Cursor(Cursors.Hand.Handle)
Cursor.Current = q
Cursor.Show()
 
shouldnt it be q.Current = Cursors.Hand()
Cursor.Hide()
q.Show()
 
I've been doing some testing and with a fresh datagrid - the MouseMove changing the cursor does work. However this is with no tablestyles applied and nothing set to the datasource. Once I set a datasource the cursor no longer changes - could this be a bug in the DataGrid?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top