0

I have a datawindow with a row that contains a dropdown list, 2 buttons and some checkboxes. I want to enable the buttons after selecting something from the dropdown list. But I also need to insert a new row and enable the buttons for that row. How can I do that?

I've tried dw_scope.Modify("b_yes.Enabled=Yes"), but this enables the buttons for all rows, when I just want to enable only for the new row.

Thanks!

Seki
  • 11,135
  • 7
  • 46
  • 70
XLD_a
  • 195
  • 1
  • 4
  • 16

2 Answers2

0

Add a 'hidden' string column to the datawindow, let's call it 'enable'. In the 'enabled' property of the button you can put an expression similar to this:

if( enable[0] = 'Y' , 'Yes', 'No' )

This will enable/disable the button based on the value of the 'enable' column in the same row.

In your code you will need to set the value of the 'enable' column based on whatever criteria enables/disables the button. Generally you do this via the SetItem method or with dot notation.

Matt Balent
  • 2,337
  • 2
  • 20
  • 23
  • Hi! Thanks, but i only have a checkbox for enable called 'enabled' for the buttons. I can't put expression for it. I can only put expression for 'visible'. – XLD_a Oct 26 '18 at 12:01
  • Use same method as I described except use the checking/unchecking of the box to set the enabled column value. – Matt Balent Oct 26 '18 at 12:11
0

Try the IsRowNew() DataWindow expression function:

dw_scope.Modify("b_yes.Enabled='0~tif(IsRowNew(), 1, 0)'")

This will default the Enabled property to disabled (0), and only enable it (1) if the row is new. Add whatever other expressions in the if() for existing rows, i.e.:

dw_scope.Modify("b_yes.Enabled='0~tif( (IsRowNew() ) or ( some_other_column = ~~'some value~~' ), 1, 0 )'")

Note: this last expression won't "kick in" when the DDLB value is selected until column focus is changed after making the selection. If you want to capture the selection itself without leaving the DDLB, you'll have to hook into the selectionchanged event.

Frank Alvaro
  • 468
  • 4
  • 12
  • Thanks, but when I insert a new row, the button is disabled. And the buttons for the previous rows are disabled too. What I want is that the buttons for previous rows to be disabled, and only the button for new row to be enabled. – XLD_a Oct 26 '18 at 12:46
  • :-? I think my syntax for `Enabled` was incorrect - values are `'Yes'` or `'No'`, not `1` or `0`... Did you catch that mistake I made (apologies)? ...updated my original answer – Frank Alvaro Oct 26 '18 at 13:29
  • no need to apologize. still not working...the syntax is incorrect. – XLD_a Oct 26 '18 at 13:43
  • @XLD_a - DOH! I forgot to wrap the entire expression in single-quotes :\ Edited my answer (and ran it through a full test this time 8| ). – Frank Alvaro Oct 27 '18 at 14:55