how do i add/subtract a column from a datawindow during runtime?

i need to do this because the number of columns would depend on the user... thanks!!
Who is Participating?
BhattiConnect With a Mentor Commented:
Make an External Datawindow say with 20 columns.
Which you want to show Set the Property Visible to 1.
( dw_1.Modify("column_name.Visible=1")

Rest columns which you don't want to show set Visible = 0

Header you can also change at run time.

Header alsmost are text objects.

Say you have Headers as t_text1, t_text2, and so on.

dw_1.Modify("column_name.Text='" + ls_text + "'")

You know which column when to display and with which text.

If you need any further explainations, please let me know. THANKS

Best regards

At runtime add or delete a column is a question. May exist a complex way to do it but if you want to know the No. of column in the active DW which are visible and (Think that visible are the columns you want and nonvisible are abstracted columns).

Best way:

Which columns you want to abstract, set the property visible to false.

// under some comditions

//You can do it also dynamic.

Now you can with Column.Count property know the number of columns in your datawindow

ls_colcount = dw_1.DESCRIBE("DataWindow.Column.Count")

Change the ls_colcount to long as ll_ColCount =LONG(ls_colcount)

//Now you can know which columns have the property visible and how many have the property nonvisible.

With For loop you can collect the number of columns visible and nn visible with the property visible:

STRING ls_status

ls_status = dw_1.DESCRIBE("Column_name.Visible") //will returmn 0 or 1

This will return string check it as string is it '0' , it is not visible in datawindow
It is '1', it is visible.

Now the visible number of column depend on the USER.

If you have question or you need some explaination, please let me know.

Best regards


You can dynamically build dw in runtime by dw.Create command. Check pb online help for detailed explanation of how to use create. With this u can create dw during run time for required columns.

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

choklitteAuthor Commented:
umm... where can i find the pb online help..? thanks!!

Just Press f1 and search for Create in your Poerbuilder development environment.

How work the CREATE statement to create a datawindow.

In you case:

STRING  ls_sql, ls_syntax, ls_error, ls_err
IF This_condition THEN
     ls_sql = 'SELECT tableA.column1, tableA.column3, tableA.column4' + &
     'FROM tableA WHERE column = condition and column < condition'
ELSEIF that_condition THEN
     ls_sql = 'SELECT tableA.column5, tableA.column7, tableA.column8' + &
     'FROM tableA WHERE column = condition and column >= condition'

ls_syntax = SQLCA.SyntaxFromSQL(ls_sql, 'Style(Type=Form)', ls_error)
IF ls_error > "" THEN
    Messagebox("ERROR", "ERROR")
    dw_abc.CREATE(ls_syntax, ls_err)
    IF ls_err > "" THEN // Write ERROR message

You need to modify the datawindow with some Modify functions.

Best regards.

Hi Bhatti
You r script is correct.
It will work properly.
We have a similar situation, that the customer will select what r the  cols. required on a particular report. According to the selection we are doing the following.

1. Dynamically build sql to a string variable.
2. Create a dynamic dw with create
3. SetTransObject and retrieve.

Similar like your script.

Also, we have a situation to place particular dwos with pre-defined format. Based on user selection we are changing the dwo.

In one type of Composite Report. We are creating dynamic composite report based on user selection during runtime. So all script what u mentioned is correct. But lots of scripting required to format and align and coloring of the cols. That is y i did not add my full script in my answer.

Try with this method, it will work, but lots of pain on maitaining the code. But otherthan this only way is hiding (as u said).


choklitteAuthor Commented:
but is there a way to create a datawindow where i don't need to get columns from the database? i'm planning on using the external datawindow since i don't need tables. the only problem is i have to make the datawindow change the number of columns (and its headers) during runtime... can this be done..?
choklitteAuthor Commented:
so i really can't add or delete columns? because the columns might extend up to 50, or even 100, depending on the user... so if that's the case, i'll have to make 50 columns in the datawindow painter then just set them to visible/invisible?
Yes I think that you should work with visible/invisible of column prperty.

Add a column a runtime and delete a column at runtime ihave not meet a such condition.

If you are setup your mind to work with External datawindow and with visible/invisible property then:

Please select a Grid datawindow for your external DW.
As I wrote above how to make them visible and invisible.

Question: What with the datatype? All columns are string or Numbers or date or mix?

I think you can 99 columns defined in external datawindow..

Make the parts of the as say, 5 for string 5 for integer or 10 for string and 4 for integer and 2 for datetime.

You are getting some data from some where and storing them and then transfering to the external datawindow. You know which data go to where. You know which name you want to give to the column.

If you have Grid datawindow form then Datawindow will show only the columns having Visible=1 property.

You can also change the name of the header.

Make first External datawindow with a good alignment and width and height as required.

Try to do this, little hard.

I shall look also further for more better solution if exist.

Best regards

choklitteAuthor Commented:
ok, i'll just do the visible/invisible one. so, how can i change the header? can i use dw.Modify?
Yes use the Modify function. In Help for Modify function you find detail.

Anyhow you can write:

If you dw named dw_1:

dw_1.Modify("Text_field_name.Text='" your_header_text" + "'")

This will change the header text  of the column you want to change.

Every header must have a name. ( you can also named to remember as text1, text2, text3 and so on or you know better).

If you become any question for visible/Invisible or other questions for text fields(Header) please let me know.

Best regards

choklitteAuthor Commented:
thanks bhatti!!
Build a DataWindow Object from a SELECT command with computed columns.

string ls_sql, ls_style, ls_error, ls_syntax
SQLCA.DBParm="Connectstring='DSN=easdemodb v3;UID=dba;PWD=sql'"

ls_sql = "SELECT 'a' as a, 'b' as be, 3.14 as pi"
ls_style = "style(type=tabular)"

ls_syntax = SQLCA.SyntaxFromSQL(ls_sql, ls_style, ls_error)
dw_1.create(ls_syntax, ls_error)
dw_1.object.a.tabsequence = 10    // set the taborder for all columns

Hi ddbeira,

What do you want to say?

Please explain.

Hi Bhatti,

Based in your suggestion for external datawindow, to build the datawindow object from SyntaxFromSql with a select statement only based in computed columns. After defined the 'result set' authorized for that user, build the SELECT statement with computed columns in the same sequence/data type of that.  The length of strings or numbers specified in the 'result set' will be used to define the columns width. The 'as' clause will be used as columns headers. The static text syntax, like title, may be obtained with DWSyntax. Because the taborder is zero (it is a report) the tabsequence property must be defined for all the columns. After the CREATE, it is possible load the primary buffer with Import, SetItem or data expression (or Retrieve).

Best regards

PS.: Sorry, this is the best that I can write.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.