Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2920
  • Last Modified:

Dynamically populate DropdownListbox

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
colettim
Asked:
colettim
  • 5
  • 4
  • 3
  • +3
2 Solutions
 
Vikas_DixitCommented:
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
 
ptbarnumCommented:
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
 
Vikas_DixitCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
colettimAuthor Commented:
I'm using PB 7.0.3.  Thank you..
0
 
colettimAuthor Commented:
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
 
Vikas_DixitCommented:
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
 
namasi_navaretnamCommented:
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
 
namasi_navaretnamCommented:
Within dropdownlist box NULL is represented by enumerated type Null!

Regards-
0
 
namasi_navaretnamCommented:
Or this

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

regards-
0
 
diasroshanCommented:
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
 
colettimAuthor Commented:
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
 
colettimAuthor Commented:
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
 
namasi_navaretnamCommented:
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
 
namasi_navaretnamCommented:
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
 
diasroshanCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now