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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing and setting value for datawindow control

Status
Not open for further replies.

chedderslam

Programmer
Jun 16, 2008
24
US
I have added a datawindow control to my form. I am trying to set its value to that of a string.

I have tried this:
dw_1.dataobject = w_test
and this:
dw_1.text = w_test.tabpage_result.mle_3.text

w_test is the parent window.

Basically I want to set a string value to the datawindow control to save it out as xml. Any help is appreciated.
 
To save to XML, use the SaveAs( ) function for the DataWindow:

String ls_filename

// get the file name
ls_filename = sle_name.Text

// save
dw_1.SaveAs( ls_filename, XML!, TRUE )
// this should save as an XML.
// the TRUE is to keep column headings.
 
But this is a data window control, not object. How do I get the string into their to save it out?
 
First you have to create a datawindow object. Sounds like one with an external data source is what you want. The dw object needs to have at least one column in it of type string.
Associate the dw object with the datawindow in the painter.

When you open the window, do a dw_1.insertrow(0). This will create a new row (row # 1) in the control. Now you can assign the string to the column using a Setitem statement. Once the string is in the datawindow column you can do the saveas stuff.

Matt

"Nature forges everything on the anvil of time
 
I'm not quite sure how to create a data window object. I can create a datawindow control, but can't get it to work.

I found something called a datastore, but I get a null reference error when I run the app. Here is what I have:


datastore_1 = create datastore

datastore_1.dataobject = "w_test"

datastore_1.insertrow(0)

datastore_1.object.data.text[1] = tab_data.tabpage_result.mle_3.text

datastore_1.SaveAs( "quote.xml", XML!, TRUE )

Error:
---------------------------
PowerBuilder Application Execution Error (R0002)
---------------------------
Application terminated.

Error: Null object reference at line 41 in clicked event of object cb_1 of w_test.
---------------------------
OK
---------------------------
 
You have to create an actual DataWindow object... Right now you're just assigning nothing to a DataWindow control and/or DataStore.

Basically, a DataWindow control (the item you place on your window) and/or DataStore are simply containers for the actual DataWindow object. (yes, it's confusing at first... With the DataWindow control and DataWindow object)

You will need to create a new DataWindow in the DataWindow Painter. Since I don't know what version of PB you're using, I can't give you the steps to create a new one. In any version, when you open the Painter, you'll be asked what type you would like to create. In this instance, you're looking to create an external DataWindow. Then, you'll define the columns. Then you'll save it. Then you'll assign your control to the object. (.DataObject property of either DataWindow or DataStore)

The typical naming scheme for DataWindow objects (d_) that I've seen is d_datawindow_name, whereas the DataWindow control (dw_) is typically named like dw_control.

Then, once you have the object assigned to it's container, you can reference the values like so:

String ls_test
Long ll_row

ll_row = dw_1.InsertRow( 0 )

// set value of column named column_name
dw_1.SetItem( ll_row, 'column_name', 'some value' )
// set the value of column #2
dw_1.SetItem( ll_row, 2, 'another value' )

// get the value of the first column
ls_test = dw_1.GetItemString( ll_row, 1 )

MessageBox( 'Column #1...', ls_test )

// use the SaveAs( ) function of the DataWindow/DataStore to export the data to XML.
 
Thank you so much for the long reply.

I am using powerbuilder 9.

Here is what I have done after reading you advice:

I have created datawindow d_incomingxml, freeform, external data source(incomingxml string).

On the main app form, I have added the datawindow control dw_1. I have set the data object for the control to d_incomingxml.

I have a command button that calls a function and sets tab_data.tabpage_result.mle_1.text to the returned xml.

I guess I need to somehow get the string into the data window so I can save it out. I'm not sure how to proceed.

Thanks again.
 
You're looking for the ImportFile( ) method. Try something like:

String ls_filename

ls_filename = 'C:\Some\Directory\filename.xml'

dw_1.ImportFile( XML!, ls_filename )
 
The xml I am trying to save out is the return of a function call. It is not in an external file. I'm not clear on how importfile would apply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top