Solved

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

Posted on 2002-04-24
16
627 Views
Last Modified: 2013-12-26
i need to do this because the number of columns would depend on the user... thanks!!
0
Comment
Question by:choklitte
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 4

Expert Comment

by:Bhatti
ID: 6965259
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
dw_1.Modify("column_name1.visible=0")
dw_1.Modify("column_name2.Visible=0")

//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

Bhatti

0
 

Expert Comment

by:pjaishankar
ID: 6974640
Hi
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.

0
 

Author Comment

by:choklitte
ID: 6976487
umm... where can i find the pb online help..? thanks!!
0
 

Expert Comment

by:pjaishankar
ID: 6976708
choklitte

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

Thanks
Jai
0
 
LVL 4

Expert Comment

by:Bhatti
ID: 6976782
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'
END IF

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

dw_abc.SetTransObject(SQLCA)
dw_abc.Retrieve()
   
You need to modify the datawindow with some Modify functions.

Best regards.

Bhatti
0
 

Expert Comment

by:pjaishankar
ID: 6977119
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).

Thanks
Jai

0
 

Author Comment

by:choklitte
ID: 6980078
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..?
0
 
LVL 4

Accepted Solution

by:
Bhatti earned 60 total points
ID: 6980313
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

Bhatti
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:choklitte
ID: 6980342
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?
0
 
LVL 4

Expert Comment

by:Bhatti
ID: 6981206
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

Bhatti
0
 

Author Comment

by:choklitte
ID: 6983208
ok, i'll just do the visible/invisible one. so, how can i change the header? can i use dw.Modify?
0
 
LVL 4

Expert Comment

by:Bhatti
ID: 6985709
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


Bhatti
0
 

Author Comment

by:choklitte
ID: 6986122
thanks bhatti!!
0
 

Expert Comment

by:ddbeira
ID: 7250435
Build a DataWindow Object from a SELECT command with computed columns.

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

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

dw_1.insertrow(0)
0
 
LVL 4

Expert Comment

by:Bhatti
ID: 7250986
Hi ddbeira,

What do you want to say?

Please explain.

Bhatti
0
 

Expert Comment

by:ddbeira
ID: 7251076
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
ddbeira

PS.: Sorry, this is the best that I can write.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now