1. B P
  2. PowerBuilder
  3. Thursday, 13 January 2022 04:35 AM UTC

How to get position of cursor in edittext style box of datawindow?


I want to open a small dropdown list at current position as I type with . (.dot notation).. I am unable to find cursor position in datawindow column

with edit style... Any advise ? 

Its same as how we enable autoscript and as we type .(dot) powerbuilder enable small dropdown with all options... PB is able to open it at same position I type . but how can I find that position in editable column?

René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 13 January 2022 06:32 AM UTC
  2. PowerBuilder
  3. # 1

Use the Position function to get the position number of the character immediately following the insertion point.


But I think you want to get the (x,y) position of the cursor? I don't know a way to get this.

Maybe you can use functions GetCursorPos or GetCaretPos of windows API.


  1. Olan Knight
  2. Monday, 17 January 2022 21:41 PM UTC
I tried top get his to work in version 12.1 of PowerBuilder and was not able to do so. The results are skewed by a variety of factors, including the existing borders, title, and the status bar. I'm sure there were other factors of which I was unaware. The end result I had was.....not acceptable nor consistent.

Like you, I'd love to have a built-in PowerBuilder function that returns the X and Y coordinates of the cursor within the current window:

ll_rc = window.CursorPosition (x pos, y pos)

Even better would be a version that works on any visual object:

ll_rc = visual_object.CursorPosition (x pos, y pos)

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 18 January 2022 01:17 AM UTC
  2. PowerBuilder
  3. # 2

So I imagine that you want to pop-up some little window that holds the ddlb / dddw ?

If your "Edit style box" is multi-line, it's not going to be easy to figure out at which x and y-position you would have to pop up that little window: You can get the position of the cursor in the text, but you don't know if for example position 100 is on line 1, 2 or 3 and depending of the width of your edit column/control, position 100 could be more to the right or left, etc. It would also depend on font sizes, fonts themselves, what text has been typed ("III" takes up less width than "ABC"), etc.

If your "Edit style box" is single-line, it might be possible to figure out at which x and y-position you would have to pop up that little window: For the Y position, you can look at the Y of the dw control, add the Y position of the column and/or consider on which row you're editing and sum a certain amount of height per row.
You can get the X position of the cursor by first reading all the text on the left of the cursor position. Then, depending on font, font-size and contents of the actual text that you just read, it should be possible to calculate the width of that text. Years ago, I heard of some library called 'Latex' to do stuff like that. Roland Smith has some example on his website to manage auto width columns https://www.topwizprogramming.com/freecode_dwgridxp.html. Maybe there's something there you could use.

Or ... what I'm thinking: Would it work if you have some "hidden" column somewhere, with 'auto-size width" set to true and assign the "left-text" to it and then read the width?

The 2 API functions suggested by Ren'e look very promising too, but even if I'd be able to get the coordinates relative to the screen, I wouldn't know of an easy way to convert that to the powerbuilder x and y values you need. (It should be possible, but I know too little of DPI and pixel widths depending on monitors, etc.).

Just ideas ...



  1. John Fauss
  2. Tuesday, 18 January 2022 03:51 AM UTC
Code in the "String Break" example program that I posted in CodeXchange a little over a year ago could help you figure out the length and height of each line of text in a single or multi-line-edit control or DW column using the Edit style, regardless of the font typeface, point size and other attributes (bolding, italics, underlining).


  1. Helpful 1
  1. Miguel Leeuwe
  2. Tuesday, 18 January 2022 03:57 AM UTC
Wow, that looks very promising John. If I get some time I'll play around with it. (not today though :)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.