1. Guillermo Pereira
  2. PowerBuilder
  3. Thursday, 11 March 2021 22:39 PM UTC

Hi Guys, I am using PB 2017 R3

I have a grid DataWindow with a DropDownDataWindow. Depending on the selection, I should hide or display a couple columns.

The issue is: When I try to show them back again, the columns lost the original position and they are displayed at the very right side. 

My grid datawindow Column list is:
"status(dddw)| code | first_name | last_name | BirthDate | Gender | Address | Phone"

dw_1.Itemchanged (event)

The code is:

ls_col_name = GetColumnName( )
CHOOSE CASE ls_col_name
   CASE "status"
      il_value = LONG( data )
         IF il_value = "Inactive" THEN
            dw_1.modify("BirthDate.visible = '0'")
            dw_1.modify("Gender.visible = '0'")
         ELSE // active
            dw_1.modify("BirthDate.visible = '1'")
             dw_1.modify("BirthDate.visible = '1'")
         END IF

   CASE...


END CHOOSE

After selecting "active" the columns comes back, but after the last column (Phone)

"status(dddw)| code | first_name | last_name | Address | Phone | BirthDate | Gender "

Any idea why is this happening? any solution?

Thanks, 

GP

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 17:05 PM UTC
  2. PowerBuilder
  3. # 1

Hi Guillermo;

  I would suggest the following ...

1) Retrieve the Datum in a DWO within a DataStore

2) Perform a ShareData() from the DS to the DWO in the DC.

// play with the column display as required. To rest the layout ...

3) Perform a ShareDataOff()

4) Reset the DWO in the DC. 

   <DC>.dataobject = ""

   <DC>.dataobject = "<Your DWO>"

5) Perform another ShareData() from the DS to the DWO in the DC.

HTH .. Just my $0.02

Regards ... Chris

 

 

Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 15:33 PM UTC
  2. PowerBuilder
  3. # 2

Hi Guillermo...Benjamin is correct as I have used this in the past. The only additional columns you have to hide are the ones that are to the right of the two you have hidden (versus every column) and then set their visible property in the order you wish to see them. And so in your scenario, when you want to make Birthdate and Gender visible again in the same order you would first hide Address and Phone and then make the columns visible in the following order: Birthdate, Gender, Address and Phone.

So your code might look like this:

ls_col_name = GetColumnName( )
CHOOSE CASE ls_col_name
  CASE "status"
     il_value = LONG( data )
     IF il_value = "Inactive" THEN
         dw_1.modify("BirthDate.visible = '0'")
         dw_1.modify("Gender.visible = '0'")
     ELSE // active
         dw_1.modify("Address.visible = '0'")
         dw_1.modify("Phone.visible = '0'")
         dw_1.modify("BirthDate.visible = '1'")
         dw_1.modify("Gender.visible = '1'")
         dw_1.modify("Address.visible = '1'")
         dw_1.modify("Phone.visible = '1'")
     END IF

  CASE...

Agreed...not elegant...but does accomplish the desired effect.

Regards,

Mark

Comment
There are no comments made yet.
Guillermo Pereira Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 15:22 PM UTC
  2. PowerBuilder
  3. # 3

Hi guys, 

Thanks for the feed back, since this is the current behavior I'm doing this trick to make it work and want to share this with you in case a similar case come in the future.

Instead of make them visible or invisible let's make it so thin that can not be seen.

In the Open event I'm saving the width of these column widths in a couple instance variables:

open event

is_BirthDate = dw_1.Describe("BirthDate.Width")
is_Gender = dw_1.Describe("Gender.Width")

and use it in dw_1.Itemchanged (event)


ls_col_name = GetColumnName( )
CHOOSE CASE ls_col_name
   CASE "status"
     il_value = LONG( data )
     IF il_value = "Inactive" THEN
        dw_1.modify("BirthDate.width = 0")
        dw_1.modify("Gender.width = 0")
     ELSE // active
        dw_1.modify("BirthDate.width = " + is_BirthDate )
        dw_1.modify("Gender.width = " + is_Gender )
     END IF

CASE...

END CHOOSE

Thanks again for your help :)

Comment
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 09:20 AM UTC
  2. PowerBuilder
  3. # 4

Hi Guillermo,

a possible workaround I can think of would be to hide every column and then set the visible attribute of the columns you want to show in the exact order you want them to be displayed, skipping the hidden columns. Not the most elegant solution but should work. 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 00:46 AM UTC
  2. PowerBuilder
  3. # 5

Hi, Guillermo -

This is happening because this is way Grid DataWindows work.

As you've seen, when you hide a column object, the DataWindow Engine (DWE) "collapses" the grid to effectively remove the empty space that would have been left behind, thus changing the X-position of all column objects that were displayed to the right of the column that has now been hidden.

The Grid style does not permit columns to "overlay" each other (if it did, it wouldn't be a grid). When you "restore" a hidden column, i.e., make it visible, the space the hidden column originally occupied is now being utilized by another column. Instead of bumping all of the columns to the right to make room, the DWE instead assigns the first available space to the now newly-visible column, which is of course, to the right of all of the other already visible columns.

It is technically possible to make a grid DW behave as you are wanting, but it is not a simple task. You would have to: 1) make the restored column visible (which places it to the far right edge), 2) manipulate via code the X-position of all of the column objects that are positioned "in the way", by an amount equal to the width of the restored column, then 3) re-position the restored column.

It's not rocket science, but it's not trivial either.

If you're familiar with the PFC, there is a DW Grid Service that hides/shows, re-orders columns, etc., and I suggest you examine that code to gain some insight on how you might accomplish what you are wanting to do.

Another idea would be to start with multiple, identical copies of the grid DW, remove the column object (not the column definitions, just the presentation objects) in one DW, for each possible configuration you need to support. Use a DataStore to hold the actual data, then swap out the DataObject assigned to the DataWindow control, using ShareData. If done properly, it should appear as if the columns were hidden and restored. As Chris Pollach is fond of saying... Food for thought.

Regards, John

Comment
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.