Results 1 to 6 of 6

Thread: Which control to use to allow user to pick two values or input your own?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    9

    Which control to use to allow user to pick two values or input your own?

    It maybe a stupid question but i am Android developer new to VB.NET. I have a scenario in which i display a form as dialog and want to allow user to pick two value suppose two football teams from a predefined list of all football teams. I can use check boxes i know but there is one more thing.
    If a football is not present in predefined data then user should be able to enter team name manually to add it and it will be saved in database table and next time user won't have to type that team name again because it will be in predefined data since it is coming from database.
    Which control i have to use? If i use check boxes for 10 or 20 teams it needs so much space. Should i use listbox if it is possible to add items in it at runtime and also save those items into database when form closed and retrieving those items from database when next time form will be loaded.
    What is best approach in this scenario. Any help is appreciated.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Which control to use to allow user to pick two values or input your own?

    Welcome to VBForums

    While Checkboxes would be possible, they are harder to set up for this kind of thing than RadioButtons (which automatically ensure only one item can be selected in their group).

    However, as you want the user to be able to add items the list, it would be easier still to use a ListBox or a ComboBox (a Drop-Down List), because then you don't need to worry about adding new controls (and maybe scrollbars etc) just to allow the extra data.

    In terms of allowing the user to add new items, a ComboBox is easier because it already has that functionality... just set the DropDownStyle property to DropDown or Simple (DropDownList doesn't allow adding a new item). A ComboBox also takes much less screen space than the alternatives (unless you use Simple), which sounds like it might be important to you.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Which control to use to allow user to pick two values or input your own?

    There isn't really any one control that will do all that for you. Multiple selection and addition aren't really compatible.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Which control to use to allow user to pick two values or input your own?

    That's a fair point, but I was assuming that there would be two controls (or groups of controls), one for each of the teams.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    9

    Re: Which control to use to allow user to pick two values or input your own?

    So after reading your response, I am thinking about adding to combo boxes, One for each football team. I can get their text values when user click on ok. Now the next thing is if user want to add his own team name, a text box & add button would do the job.
    Last question, does user input can be added into combo box immedietly when he click on add button and how can i store newly entered team or teams immedietly in my database table when user closes that form?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Which control to use to allow user to pick two values or input your own?

    You can use a textbox and button if you want (the code for the button would be something like: ComboBox1.Items.Add(TextBox1.Text) ), but you don't have to - the functionality is already in the ComboBox if you use Simple or DropDown, the user can just type directly in the "textbox" portion of it. If you do decide to use a separate textbox and button, set the style to DropDownList so that the user can't also enter items directly in it.

    If you just use the combobox, to detect if the selected item is new just check the .SelectedIndex property (-1 means either nothing is selected, or a newly added item is selected).

    For information on saving to databases (including code examples), see our Database Development FAQs/Tutorials (at the top of the Database Development forum)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width