1. Pete Yankovich
  2. PowerBuilder
  3. Tuesday, 29 June 2021 12:32 PM UTC

PB 2017R2, I have a DW where all columns are protected based on data values for a given row.  If this occurs, the row cannot be selected.  If columns are not protected, then the row can be selected.  I need to be able to select any row.

Is there a better approach to protecting rows and yet be able to select rows, possible with the Row Manager service?

Thanks for any help.

Pete

Andrew Barnes Accepted Answer Pending Moderation
  1. Wednesday, 14 July 2021 20:03 PM UTC
  2. PowerBuilder
  3. # 1

Another way around this sort of issue is to put in a dummy column in your DataWindow's SELECT and if all the other columns are protected, unprotect the dummy column.  I've used this technique once or twice, and it works reasonably well.  Make the field small, transparent, and with no border, and it will be barely noticeable. 

Comment
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Monday, 5 July 2021 12:26 PM UTC
  2. PowerBuilder
  3. # 2

Adding to the replies of Miguel and René, you can force a setrow( getclickedrow() ) in the clicked event of the DW control to circumvent the "having to click the display column" caveat. Clicking a protected column will thus select the row and set the cursor to the display column.

Here's what I'm using in the clicked event to address this:

long ll_col, ll_protect = 0
string ls_colname, ls_protect

ll_col = getclickedcolumn( )
if ll_col > 0 then
	ls_colname = this.describe( '#' + string(ll_col) + '.name')
	
	ls_protect = this.describe( ls_colname + '.Protect' )
	// If not a number, evaluate the expression
	if not isnumber(ls_protect) then
		// Cutting off leading "1~t" or "0~t"
		ls_protect = Mid( ls_protect, Pos(ls_protect, '~t') + 1 )
		ls_protect = Mid( ls_protect, 1, len(ls_protect)-1)
		ls_protect = this.describe("evaluate(~"" + ls_protect + "~", " + string(getclickedrow()) + ")")
	end if
	
	if isnumber(ls_protect) then
		ll_protect = long(ls_protect)
	// else: give up :)
	end if
end if

if ll_protect = 1 then
/*
 adding
 	or ll_col = 0
 to the condition will also select the row
 if any non-column part of the row was clicked,
 which might be useful
*/
	this.setrow( getclickedrow() )
end if

 

This might be too elaborate even, a simple 

setrow( getclickedrow() )

in the clicked event probably does the trick already. Might even work without any display columns, but I haven't confirmed this.

Comment
  1. Benjamin Gaesslein
  2. Monday, 5 July 2021 13:09 PM UTC
PS: setrow( getclickedrow() ) does indeed work even when all columns are protected (tab-order set to 0, too). Both the currentrow() expression function and dw_x.getrow() correctly report the row number that was clicked before.
  1. Helpful
  1. Pete Yankovich
  2. Tuesday, 13 July 2021 12:14 PM UTC
That did the trick! Thanks Ben.
  1. Helpful
  1. Benjamin Gaesslein
  2. Wednesday, 14 July 2021 13:35 PM UTC
Glad I could help. You can accept this answer as a solution if it worked for you.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 29 June 2021 19:59 PM UTC
  2. PowerBuilder
  3. # 3

Over the years, I've found always the same problem with the 'protect' attribute: if the cursor is within the column you are trying to protect it fails. So if you want to protect all columns, you have a problem.

Therefore, what I do, is to record all tabsequences of all columns in an array in the constructor of the dw. When I want to 'protect' them all, what I do is use the tabsequence property setting it to 0. I'm not sure though if you can still select a row when all columns have tabsequence 0 (no time to test), but I do know it gives way less problems.

When you want to re-enable the columns, you use the array with tabsequences to restore their original values.

Just an idea,

Miguel

Comment
  1. Pete Yankovich
  2. Wednesday, 30 June 2021 14:23 PM UTC
Thanks for all your suggestions. I'm sure they are all good approaches to my issue. I made one column display only, instead of protected and now able to select any row. The one minor drawback to this is that the display only column must be clicked to select the row. But, it should work fine.

  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 30 June 2021 14:42 PM UTC
Hi Pete, do a setcolumn() in the rowfocuschanged just before protection has to be applied?
  1. Helpful
  1. Mark Goldsmith
  2. Wednesday, 30 June 2021 14:48 PM UTC
Hi Pete...Miguel is correct (and it's the approach I usually take) in that setting all the tabsequence values to 0 will still allow you to select the row and so if having to click on the one display column turns out to be problematic you can use this approach.



Regards,

Mark
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Tuesday, 29 June 2021 18:56 PM UTC
  2. PowerBuilder
  3. # 4

Renee's solution works very well.

Create a  computed field.  Make this a numeric column.
Create an expressioin that results in zero or one such that zero means NOT SELECTABLE and one means SELECTABLE.

Set the taborder to zero on this field
Create an expression on the PROTECT property of the row in the detail band and set the expression to be "selectable".

Good Luck,

Olan

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 29 June 2021 14:00 PM UTC
  2. PowerBuilder
  3. # 5

Hi Pete,

Yes, this is strange behaviour. We had also such problems. Sometimes it is possible to select such rows, sometimes not.

You need at least one column object that is not protected and can get the focus. You should set it to DisplayOnly as John recommended. But you can't use expression for DisplayOnly property so probably you have to add a dummy column only for this usage. 

Or you could try to add two column objects for one of your columns - one object for edit and one for display. Use expression for visible property to show the column objects dependend on columns protection.

HTH,

René

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 29 June 2021 13:40 PM UTC
  2. PowerBuilder
  3. # 6

Hi, Pete -

Use the DisplayOnly property in one column object instead of Protect. The column can then receive focus but the value cannot be changed. 

Comment
  1. René Ullrich
  2. Tuesday, 29 June 2021 13:49 PM UTC
But you can't use an expression for DisplayOnly.
  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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.