Allow No Selection for ComboBox - what is the value?

I have two comboboxes on a form. Both are filled from tables. I'm trying to give the option to not choose a value from one of the comboboxes. Both comboboxes have keyvalues pulled from the tables. What is the value of the keyvalue if no selection is made? Is it null, 0, -1, etc?

OR...

Is there a way to add a "none" selection to each box and then use that value?

I need to have a value if no selection is made to use in a query.

Thanks

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 7:39PM
    David here is what i use, it might help you,
    when i create the query paramaters i point them to precreated report variables,
    whose values are preset to predetermined values, i modify the variables from either combobox selections
    or radio btn selections, just remember when passing string values to the variabled to
    use extra string delimiters.
  • edited 7:39PM
    Thanks, gordk. I ended up initializing the keyvalues of the comboboxes that are used in the query in the dialogpage onshow event. That seems to be working. I don't know if there are any pitfalls with that approach. I might try using variables as you suggested. I'm not sure what you mean by extra string delimiters but might figure it out once I try it.
  • gordkgordk St.Catherines On. Canada.
    edited 7:39PM
    David FYI when you create categorized variables in fr if you give them a string value you must
    include the apostrophe string delimiters or the value will be treated as an expression and trigger the
    ogv (ongetvalue)event to try to obtain a value.
  • edited 7:39PM
    gordk
    I know to put single quotes around the value when assigning to a string variable:
    myVariable = 'ZZZ'
    
    I think that is what you are telling me. Please let me know if I'm missing something.

    I currently have the keyfields property of each combobox set to a value. The query then uses the keyvalue.
    The params property of each query is:
    DBLookupComboBox1.keyvalue
    

    The comboboxes are on a DialogPage. I initialize in the OnShow event. ComboBox1 is alphanumeric. ComboBox2 is numeric.
    procedure DialogPage1OnShow(Sender: TfrxComponent);
    begin
        DBLookupComboBox1.keyvalue := 'ZZZ'; 
        DBLookupComboBox2.keyvalue := 0;           
    end;
    

    Please let me know if there is anything wrong with that approach.

    I could create variables and pass them to the keyvalues used in the query when the user clicks the OK button on the DialogPage.

    Thanks for your replies. I'm still learning.
  • gordkgordk St.Catherines On. Canada.
    edited 7:39PM
    There really is no best approach, over the years of working with Fr I have found that if something works for you
    go with it.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.