Solved

Dynamically populate DropdownListbox

Posted on 2004-03-30
16
2,611 Views
Last Modified: 2013-12-26
I have a column in a datawindow that has the DropdownListbox edit style.  I'm populating the display and data values dynamically in code by using the Values property.  However, I want to use NULL as the data value for one of the choices.  I have the 'Empty String is NULL' checked.  How would I go about doing this?

If I use a Display Value (example 2 below), it does not work.  When I don't use a Display Value (example #1), it works fine.  For example,

1) ls_values = "chaintype.Values='~t~~'~~'"     --  Returns null

2) ls_values = "chaintype.Values='Store~t~~'~~'"  -- Returns ''

Please advise.
Thanks!


0
Comment
Question by:colettim
  • 5
  • 4
  • 3
  • +3
16 Comments
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 10717075
Hi,

Did you try using the function setValue () instead ? ( Just try it, I haven't tested it..)

dw_1.SetValue("chaintype", 1, "Store")

regards,
Vikas
0
 

Expert Comment

by:ptbarnum
ID: 10717107
I do not have a solution to this but I wanted to say that having a Null value in a column mean anything other than null /not enetered is usually not a good idea.   BTW - What version of PB are you using?
0
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 10717152
As per the PB help, The function is goung to return null  if any of the parameters are null.I guess you are using modify function  if Modify() returns '' then it means success.. then why do you say example 2 is failing ??
--Vikas
0
 

Author Comment

by:colettim
ID: 10717167
I'm using PB 7.0.3.  Thank you..
0
 

Author Comment

by:colettim
ID: 10717209
I say it's failing because in the ItemChanged event, I want the 'data' argument to be null, not ''. In example 2, I'm getting ''.

0
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 10718579
Do you Want both the values  null and blank in your ItemChanged Event ? I mean do they have seperate processing ?
IF no, you can write your logic to handle both in the same manner. And if you are saving it to database, then it should not be an issue, the blank should go as null. can you try the same once ?

Regards,
VIkas D.
0
 
LVL 15

Assisted Solution

by:namasi_navaretnam
namasi_navaretnam earned 75 total points
ID: 10718810
The trick is to use Null!

Try something like this:

dw_employee.SetValue("emp_state", Null! , "Texas")
dw_employee.SetValue("emp_state", Null! , "Texas~tTX")

regards-
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10718815
Within dropdownlist box NULL is represented by enumerated type Null!

Regards-
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10718824
Or this

dw_employee.SetValue("emp_state", 1, "Texas")
dw_employee.SetValue("emp_state", 1, "Texas~tNull!")

regards-
0
 
LVL 18

Expert Comment

by:diasroshan
ID: 10722214
hi colettim,

      what u require is a null value.... wouldn't it help  in the case of example 2 that u simply write the code..

If Trim(ls_values) = "''"  Then SetNull(ls_values) // coz u know that the value u want as null returns ''

.... or is it hard and fast that data should return a null

Cheers,
Rosh
0
 
LVL 8

Expert Comment

by:gajender_99
ID: 10722733
0
 

Author Comment

by:colettim
ID: 10723667
Wow, thanks for all the suggestions!  I'm going to try yours, namasi.  I will let you all know which one works and reward the points.  

To answer some of the questions, yes I do want to save the value of NULL in the database.  I know that is bad database design but it's the way the database table is.

Thanks again for all the prompt responses!!!
0
 

Author Comment

by:colettim
ID: 10723923
namasi,

Your suggestion worked fine except for one problem.

Here is the code that I used:

dw_1.SetValue("chaintype", 1, "Store~tNull!")

When I choose 'Store' from the chaintype dropdownlistbox and select another column, 'Store' disappears.

0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10728426
colettim,

Yes. The display value will disappear when you click on other columns. Why would you need to store Null when 'Store' is selected. Could you not store 'S' or something like that. ?

In my app it is coded as shown below, so it was not a concern.
dw_1.SetValue("chaintype", 1, "NULL~tNull!")

regards-
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10728507
If using pfc you can do this preupdate event. If using non-pfc do this before update statement is sent to the database.

long ll_count, ll_i
string  ls_null
SetNull(ls_Null)

ll_count = dw_1.Rowcount()
For ll_i = 1 to ll_count
   If dw_1.GetItemString(ll_i, 'chaintype') = 'store' then
      dw_1.SetItem(ll_i, 'chaintype', ls_null)
   End if
Next

Let me give you a risky approch but you will need to test this well.

long ll_pos
if sqltype = PreviewUpdate!      then
      ll_pos =  Pos(sqlsyntax, "='Store'")
      If ll_pos > 0 then
          replace( sqlsyntax, ll_pos, 8, 'NULL')
                   //TO debug
                    MessageBox("debug", sqlsyntax)      
      end if      
end if      


regards-
0
 
LVL 18

Accepted Solution

by:
diasroshan earned 50 total points
ID: 10729786
hi colettim,

u have mentioned above that u want itemchanged to return a null in 'data'... but i'm afraid if u use the

code ....'dw_1.SetValue("chaintype", 1, "Store~tNull!")' then ur first row will be Store and with null as

the data value... in that case ur itemchanged will not fire....

Please check the same.... if select any other value and then select 'Store' that is when data will

return u a null.... what u can do is set another value as default....

ll_row = dw_1.InsertRow(0)
dw_1.SetValue("chaintype", 1, "Store~tNull!")
dw_1.SetValue("chaintype", 2, "Godown~tG")

dw_1.Object.chaintype[ll_row] = 'G'

Cheers,
Rosh
0

Featured Post

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

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

758 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

21 Experts available now in Live!

Get 1:1 Help Now