ComboBox restrict input

Posted by: fsegui on 17 March 2021, 9:52 am EST

    • Post Options:
    • Link

    Posted 17 March 2021, 9:52 am EST

    Hello,

    I’m using combobox with databinding.

    I’m defining the comboBox like this:

    
    combo.TranslateValue = True
    combo.ItemsDataSource = comboData
    combo.ItemsDisplayMember = "DisplayString"
    combo.ItemsValueMember = "ItemData"
    
    

    I need to restrict the user inputs to number only or to short date.

    For that, I set the datatype to int32 or datetime but that’s not taken into account due to the translatevalue option set to true.

    How can I proceed?

  • Posted 18 March 2021, 5:41 am EST

    Hello,

    The TranslateValue property translates C1.Win.C1Input.C1TextBox.Value to C1.Win.C1Input.C1TextBox.Text i.e. why the Datatype property is not taken into account because it works at value level only. If you set the TranslateValue to false then the program will work as expected.

    Please find the attached sample implementing the same.

    Regards,

    Prabhat Sharma.

    C1ComboboxDemoNew.zip

  • Posted 19 March 2021, 4:57 am EST

    Hello,

    Well, in my case value and display member are not the same. So if I set translateValue to false, when the user selects an item, the list does show the display member but when selected, the combobox displays the value and that’s not suitable for me…

  • Posted 19 March 2021, 9:01 am EST

    Hi,

    If I understand your request correctly, try this solution with regex:

    c1ComboBox1.ItemsDataSource = comboData;
    c1ComboBox1.TranslateValue = true;
    c1ComboBox1.ItemsDisplayMember = "DisplayString";
    c1ComboBox1.ItemsValueMember = "ItemData";            
    c1ComboBox1.MaskInfo.RegexpEditMask = "[0-9]{0,4}";
    
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels