PowerBuilder – Simple ‘Windows Standard’ Row Selection

Posted on Friday, May 21st, 2010 at 8:20 pm in

Allowing for ‘Windows Standard’ muli row selection is pretty straight forward.  By ‘Windows Standard’ I mean you can select a range by clicking on a row, holding the shift key and clicking on a second row to select all the rows between the two or by holding down the control key and clicking you can select multiple rows (or unselect one previously selected without unselecting all the others).  Anyway the code is in the clicked event of the datawindow.

ll_selectedrow = getselectedrow(0)
// select range
IF KeyDown(keyShift!) THEN
   IF ll_selectedrow = 0 THEN
      This.SelectRow(row, True)
   ELSE
      This.SelectRow(0, False)
      IF row > ll_selectedrow THEN
         FOR ll_rc = ll_selectedrow TO row
           This.SelectRow(ll_rc, True)
         NEXT
      ELSE
         FOR ll_rc = row TO ll_selectedrow
            This.SelectRow(ll_rc, True)
         NEXT
      END IF
   END IF
// multi select
ELSEIF KeyDown(keyControl!) THEN
   IF This.IsSelected(row) THEN
      This.SelectRow(row, False)
   ELSE
      This.SelectRow(row, True)
   END IF
// single select
ELSE
   IF This.IsSelected(row) THEN
      This.SelectRow(0, False)
      This.SelectRow(row, True)
   ELSE
      This.SelectRow(0, False)
      This.SelectRow(row, True)
   END IF
END IF
You might also be interested in

8 Comments

Add your comment

  1. merovingen - April 15, 2011 at 8:14 am

    Hi, this code works properly, but my problem is to select rows without mouse, using only KeyShift! and KeyDownArrow! or KeyUpArrow!. Tried to implement under pbm_keydown event.

  2. Matt Balent - April 15, 2011 at 10:24 am

    Do you have an example of what you have tried?

  3. merovingen - April 19, 2011 at 9:58 am

    Something like this:

    IF KeyDown(keyShift!) AND KeyDown (KeyDownArrow!) THEN
    This.SelectRow(ll_row, True)
    IF ll_row > ll_selectedrow THEN
    FOR ll_rc = ll_selectedrow TO ll_row
    This.SelectRow(ll_rc, True)
    NEXT
    ELSE
    FOR ll_rc = ll_row TO ll_selectedrow
    This.SelectRow(ll_rc, True)
    NEXT
    END IF
    END IF

    Well, I know this is pretty wrong, but anyway maybe can figured out?!

  4. Matt Balent - April 19, 2011 at 12:14 pm

    Actually your code works okay for selecting rows with the shift-downarrow key combination. You need to set an instance variable to track the row which has focus (ll_row in your code). Set this after the data is retrieved and then again in the rowfocuschanged event. You also need to set ll_selectedrow if it is zero which would be when the datawindow is first populated unless you do a setrow/selectrow combination.

    To unselect I assume you want to use the uparrow which simply uses Selectrow(row,FALSE).

  5. merovingen - April 20, 2011 at 4:56 am

    hey,

    Did you mean something like this? It’s still choose all rows but not one by one..

    long row, ll_selectedrow, ll_rc

    If KeyDown (KeyShift!) AND KeyDown (KeyDownArrow!) Then
    ll_selectedrow = getselectedrow(0)
    IF ll_selectedrow = 0 THEN
    Row = Long( dw_kst.Object.DataWindow.FirstRowOnPage )
    ELSE
    This.SelectRow(row, False)
    IF row > ll_selectedrow THEN
    FOR ll_rc = ll_selectedrow TO row
    This.SelectRow(ll_rc, True)
    NEXT
    ELSE
    FOR ll_rc = row TO ll_selectedrow
    This.SelectRow(ll_rc, True)
    NEXT
    END IF
    END IF
    END IF

  6. merovingen - April 20, 2011 at 10:08 am

    and how is correct?

  7. merovingen - April 25, 2011 at 9:22 am

    Guys,

    If you have similar problem as mine, so I found the best solution how select rows in datawindow only using keyboard without mouse:

    In the Datawindow find pbm_rowfocuschanged and add this code below. That’s it. You will get already working code.

    If KeyDown (KeyShift!) AND ( KeyDown (KeyDownArrow!) OR KeyDown(KeyUpArrow!)) Then
    This.SelectRow(currentrow,TRUE)
    Return
    End If

    cheers

Leave a Reply

Top