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!

Mousepointer in grid 2

Status
Not open for further replies.

foxdbs

Programmer
Aug 5, 2004
66
CZ
Hi,
is it possible to set different mousepointer in whole grid?

If I set the .MousePointer property for grid + textboxes in columns, required pointer is inside the active cell, but not in other cells in the column. Changing of .Sparse doesn't help.
 
I believe this functionality is provided for in VFP 9, what version of VFP are you running?

boyd.gif

 
Backgroud...

While a control is selected in a grid's column, the
mousepointer specified for the control is displayed,
but when the mouse is moved over rows other than the
selected row, the MousePointer defaults to an "I-Beam".

Solution...

To accomplish what you want, you'll need to perform some 'sleight-of-hand' since a column object doesn't
have a MousePointer property.

In your form, create a property called nOriginalMousePointer and assign it the form's
current MousePointer upon initialization.

In the form's MouseMove() event place this statement:
this.mousepointer = this.nOriginalMousePointer.

In the MouseMove() event of the columns of the grid
which you want different mousepointers to display over
grid rows, place this statement:
thisform.mousepointer = (nMousePointerYouWant).

In the controls contained in the grid columns you
can either define the MousePointer during class definition, during initialization, assign it in the
control's MouseMove() event(what I've done in the example),
or at any other time you want.

Here's some code showing the concept:

Code:
o = createobject("MyForm")
o.show()
read events

* Main form
define class MyForm as form
  docreate = .t.
  autocenter = .t.
  caption = "Mousepointer in grid controls example"
  datasession = 2
  nOriginalMousePointer = this.mousepointer

  add object grdTest as clsGrid with ;
    width = this.width

  add object text1 as textbox with ;
    top = this.grdTest.top + this.grdTest.height, ;
    width = this.width

  procedure load
    create cursor temp (fld1 c(10), fld2 n(10))
    for i = 1 to 100
      insert into temp (fld1, fld2) values ("Field"+trans(i),i)
    next
    go top
  endproc

  procedure destroy
    clear events
  endproc

  * Reset mouse pointer
  procedure mousemove
    lparameters nButton, nShift, nXCoord, nYCoord
    this.mousepointer = this.nOriginalMousePointer
  endproc

  * Just to show mouse position
  procedure GrdNotify
    lparam cObjName, nXCoord, nYCoord
    this.text1.value = cObjName+" X:="+trans(nXCoord)+", Y:="+trans(nYCoord)
  endproc
enddefine

* Custom grid class
define class clsGrid as grid
  deletemark = .f.
  add object column1 as clsColumn
  add object column2 as column
  
  * Show mouse position for illustrative purposes
  procedure mousemove
    lparameters nButton, nShift, nXCoord, nYCoord
    thisform.GrdNotify(this.name,nXCoord, nYCoord)
  endproc
enddefine

* Custom column class
define class clsColumn as column
  add object Text1 as clsText


  * This column sets the form's mouse pointer
  * to simulate a desired mousepointer over a
  * control even though the control is not selected
  procedure mousemove
    lparameters nButton, nShift, nXCoord, nYCoord
    thisform.mousepointer = 6
    thisform.GrdNotify(this.name,nXCoord, nYCoord)
  endproc

enddefine


* Custom texbox class
define class clsText as textbox
  procedure init
    this.width = this.parent.width
  endproc

  * MousePointer could be set during class definition
  * or at any other time
  procedure mousemove
    lparameters nButton, nShift, nXCoord, nYCoord
    this.mousepointer = 6
  endproc
enddefine
 
In each of the columns of the Grid you have to put the code..

In all the Column.MouseMove Event put the code..
This.Parent.MousePointer = 1

This will make the mouse pointer to arraow. Those columns which are not allowed to be altered, you neeed not put that code.

If you build a column class of your own.. probably, you can put the code..

IF ! This.ReadOnly
This.Parent.MousePointer = 1
ENDIF

This will make the pointer to change to arrow for all columns which can be altered.
********************************************************
If you are using VFP8 you have an easy event handler to do things easier.

MyGrid.Init
***********
FOR EACH oColumn IN This.Columns
=BINDEVENT(oColumn,"MouseMove",This,"MouseMove")
ENDFOR

MyGrid.Destroy
**************
FOR EACH oColumn IN This.Columns
=UNBINDEVENT(oColumn,"MouseMove",This,"MouseMove")
ENDFOR

MyGrid.MouseMove
****************
This.MousePointer = 1


____________________________________________
ramani - (Subramanian.G) :)
 
PROCEDURE Column.MouseMove
THIS.Parent.MousePointer = nnn

... works great!
Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top