Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing DDDW Dynamically

Status
Not open for further replies.

getjbb

MIS
Jun 4, 2003
139
US
Hi,

I am trying to change a dddw datacolumn and displaycolumn
dynamically and then I want to see the value of the new datacolumn I have tried a number of things but nothing seems to work. It gets the original datacolumn value. Even though I change the datacolumn in the middle of the code. I have to make another selection from the dropdown to get the new value. It is as if the itemchanged event is starting from the top and reassigning the dataobject variable, data,
to the ls_data variable (with new value). Is there anyway to set data to the new value as soon as I change the datacolumn.
Could someone please help me with this.
This is being done in the itemchanged event. The code is below:

// Get the name of the field changed
ls_column_name = dwo.name

// Set a variable to the data coming in
LS_DATA = data

// Describe the data column which will be order_id (the original datcolumn)
ls_DataColumn1 = dw_1.Describe(ls_column_name + ".DDDW.DataColumn")

// Change the data column from order_id to category_id;
dw_1.object.ls_column_name.dddw.datacolumn = "category_id"

// Describe the new datacolumn
ls_DataColumn2 = dw_1.Describe(ls_column_name + ".DDDW.DataColumn")

// Get the new value of the new datacolumn
LS_DATA = data

getjbb
 
If you look at the ItemChanged! event definition, the data argument is defined as to be passed By-Value which means any changes to the original data are not automatically reflected in the data argument as it is just a 'copy'. So, modifying the DataColumn does not refresh the value in the data argument unless you re-assign to it manually using GetItemXxx() or dot-notation (GetText() may still have the same value that data argument had initially).

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Hello,

I did the following according to the reply from PowerObject:

data = dw_1.Getitemstring(dw_1.GetRow(),ls_column_name)

after changing the datacolumn to category_id and I still got the value from the original datacolumn.

Do I also have to set the displaycolumn also:
dw_1.object.ls_column_name.dddw.displaycolumn = "category_id"

It seem that I am missing something. I tried just about everything.

Again, this is PowerBuilder 9 and the code is in the ItemChanged event.

Thanks for any help in advance.

getjbb


 
What are you trying to accomplish? Are you trying to assign some data-values using the data argument? The data argument is an argument to the ItemChanged! event (like a LOCAL variable!) and assigning another value to it does not change the data in the datawindow. If you want to change the data in the datawindow, you need to do a SetItem() or use dot-notation to assign the new value to the column.

Please be more specific as to what you are trying to accomplish... For instance, see my comments in UPPER-case below:

// Get the name of the field changed
ls_column_name = dwo.name
THIS LINE IS NOT REQUIRED AS DWO.NAME WILL NOT CHANGE AND YOU CAN USE IT DIRECTLY.


// Set a variable to the data coming in
ls_Data = data
THIS LINE IS NOT REQUIRED - WHERE ARE YOU USING THE LS_DATA?


// Describe the data column which will be order_id (the original datcolumn)
ls_DataColumn1 = dw_1.Describe(ls_column_name + ".DDDW.DataColumn")
THIS LINE IS NOT REQUIRED - WHERE ARE YOU USING LS_DATACOLUMN1 VARIABLE?


// Change the data column from order_id to category_id;
dw_1.object.ls_column_name.dddw.datacolumn = "category_id"


// Describe the new datacolumn
ls_DataColumn2 = dw_1.Describe(ls_column_name + ".DDDW.DataColumn")
THIS LINE IS NOT REQUIRED - WHERE ARE YOU USING LS_DATACOLUMN2 VARIABLE?


// Get the new value of the new datacolumn
ls_data = data
THIS LINE IS NOT REQUIRED


You are not using most of the values you are capturing in the variables in your code so those lines are not actually required. You are not using a SetItem() or the dot-notation to actually set the data you want. Posting your code in the ItemChanged! in this thread will help us figure out your issue.

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Hello,

I am trying to change a datacolumn from order_id to
category_id.

The field, catalog_product# has an edit style of drop-down datawindow
and the datacolumn is order_id and the display column is order_desc.

I want to change the datacolumn to category_id and the display_column
to category_id.

I need to find out the value of category_id to pre-fill
the Category datawindow if Product datawindow is changed.

The only way I know of to get it is
to change the orignal datcolumn and then isolate the new value

The datawindow is set up as (catalog_product1, category1,catalog_product2, category2
are defined with an edit style of drop-down datawindow)

Product Category
------- --------
catalog_product1 category1
catalog_product2 category2

Below is the code:

-------------------------------------------------------

string ls_column_name, ls_data

ls_column_name = dwo.name
ls_data = data

// Right here I am trying to change the datacolumn from order_id to category_id
dw_1.Object.fax_contract_return_reason1.dddw.datacolumn = "category_id

// ???? HOW DO I ASSIGN THE VALUE FROM THE NEW DATAWINDOW TO A VARIABLE ???????
// THE GETITEMSTRING DOES NOT WORK
data = dw_1.Getitemstring(dw_1.GetRow(),ls_column_name)

new_data = data


CHOOSE CASE ls_column_name
CASE "catalog_product1"
if ls_data = '9999' then
// Here the original data value, ls_data is used
dw_1.SetItem(dw_1.GetRow(),"catalog_return_category1",ls_data)
else
// Here will like to use the new data from the datacolumn
dw_1.SetItem(dw_1.GetRow(),"catalog_return_category1",new_data)
end if
CASE "catalog_product2"
if ls_data = '9999' then
// Here the original data value, ls_data is used
dw_1.SetItem(dw_1.GetRow(),"catalog_return_category2",ls_data)
else
// Here will like to use the new data from the datacolumn
dw_1.SetItem(dw_1.GetRow(),"catalog_return_category2",new_data)
end if

END CHOOSE

-------------------------------------------------------------

Thanks in advance for your help

getjbb
 
Please see my inline comments in Bold:

I am trying to change a datacolumn from order_id to
category_id.

Does Category_ID exist in the same DDDW object? Or it is a different datawindow object?


The field, catalog_product# has an edit style of drop-down datawindow
and the datacolumn is order_id and the display column is order_desc.

I want to change the datacolumn to category_id and the display_column
to category_id.

If category_id column does not exist in the same DDDW object, you will have to first assign the right dataobject to the DDDW column


I need to find out the value of category_id to pre-fill
the Category datawindow if Product datawindow is changed.

Where is the Category_ID column? On the main dw or inside the DDDW? If it is in the main dw, you can use the GetItemXxx() function or the dot-notation. If it is inside the DDDW, you need to use the GetChild() to get a reference to the DDDW and then use GetItemXxx() function (dot-notation does not work on child datawindows). See Help on GetChild() for more info.


The only way I know of to get it is to change the orignal datcolumn and then isolate the new value

The datawindow is set up as (catalog_product1, category1,catalog_product2, category2
are defined with an edit style of drop-down datawindow)

Product Category
------- --------
catalog_product1 category1
catalog_product2 category2

Below is the code:

-------------------------------------------------------

string ls_column_name, ls_data

ls_column_name = dwo.name
ls_data = data

Here, ls_Data is actually the modified (new) text still residing in the Edit-buffer that is not yet flushed into the underlying column. It is the data entered by the user that may be different from the actual column's (old) value. All user-edits are performed in the Edit-control (for each column) and after the 4 phases of validation, it is flushed into the underlying column typically by AcceptText() or tabbing to another column. The data argument has the value the user entered and available to you to validate it.


// Right here I am trying to change the datacolumn from order_id to category_id
dw_1.Object.fax_contract_return_reason1.dddw.datacolumn = "category_id

If Category_ID is not in the same DDDW object, you will have to change the DDDW's dataobject first.



// ???? HOW DO I ASSIGN THE VALUE FROM THE NEW DATAWINDOW TO A VARIABLE ???????
What is the NEW datawindow? Are you trying to change the datawindow for the DDDW column? If you are trying to change the DDDW object, here is a sample:

dw_1.Object.fax_contract_return_reason1.dddw.NAME = &quot;<new-dddw-object>&quot;
dw_1.Object.fax_contract_return_reason1.dddw.datacolumn = &quot;category_id&quot;
dw_1.Object.fax_contract_return_reason1.dddw.displaycolumn = &quot;category_id&quot;
//
dataWindowChild dwc
//
IF dw_1.GetChild( &quot;fax_contract_return_reason1&quot;, dwc ) = 1 THEN
dwc.SetTransObject( SQLCA )
dwc.Retrieve( <arguments> )
END IF



// THE GETITEMSTRING DOES NOT WORK
data = dw_1.Getitemstring(dw_1.GetRow(),ls_column_name)

new_data = data

Here, new_data is actually the (old/previous) data that is residing in the column. The Edit-control may still be having a modified (new) data (available through the data argument) that is not flushed into the column yet.



CHOOSE CASE ls_column_name
CASE &quot;catalog_product1&quot;
if ls_data = '9999' then
// Here the original data value, ls_data is used
ls_Data is actually not original - it is the modified value by the user that has not yet made itself into the column as mentioned above
dw_1.SetItem(dw_1.GetRow(),&quot;catalog_return_category1&quot;,ls_data)
else
// Here will like to use the new data from the datacolumn
New_Data is actually the old data in the column as mentioned above
dw_1.SetItem(dw_1.GetRow(),&quot;catalog_return_category1&quot;,new_data)
end if
CASE &quot;catalog_product2&quot;
if ls_data = '9999' then
// Here the original data value, ls_data is used
dw_1.SetItem(dw_1.GetRow(),&quot;catalog_return_category2&quot;,ls_data)
else
// Here will like to use the new data from the datacolumn
dw_1.SetItem(dw_1.GetRow(),&quot;catalog_return_category2&quot;,new_data)
end if

END CHOOSE

You need to do all of the above processing inside an IF statement; otherwise, it gets executed for each ItemChanged! event on ANY column; as in:

IF dwo.Name = <column> THEN
... do stuff ...
END IF


-------------------------------------------------------------

Thanks in advance for your help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top