Symptom

How do I get the X and Y coordinates of a clicked row in a grid datawindow?

Environment

PowerBuilder

Resolution

The code sample below moves an existing static text box to the location where a user has clicked in the grid datawindow. It can be altered to use these X, Y grid datawindow coordinates for other uses.

The code sample assumes a PB application with an existing grid datawindow named dw_1 and a static text box named st_1.

1. Declare the following external function.

//GetSystemMetrics is an external function defined as below :

Function integer GetSystemMetrics (int nIndex ) Library "user32.dll

2. Place the following script in the clicked event of the grid datawindow.

long firstrow

integer li_rowheight, li_Header_height, li_border

st_1.X = dw_1.X + Integer(dw_1.Describe(dwo.name + ".x")) -

Integer(Describe("datawindow.horizontalscrollposition"))

st_1.width = Integer(dw_1.Describe(dwo.name + ".width"))

 

li_Header_height= Integer(dw_1.Object.Datawindow.Header.Height)

li_rowheight = Integer(dw_1.Object.Datawindow.Detail.Height)

firstrow = Long(dw_1.Object.DataWindow.FirstRowOnPage)

li_border = PixelsToUnits( GetSystemMetrics (5), YPixelsToUnits!)

if dw_1.border then li_border += PixelsToUnits( GetSystemMetrics (5), YPixelsToUnits!)

st_1.Y = dw_1.Y + li_Header_height + (row - firstrow ) * li_rowheight + integer (dw_1.Describe(dwo.name + ".Y")) + li_border

st_1.height = Integer(dw_1.Describe(dwo.name + ".height"))

  • Up
    1
  • Down
    0