Results 1 to 21 of 21

Thread: Add --SELECT--

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Add --SELECT--

    Hi,

    I have the following code that pulls the data from the table, however, I want the first record to be set as --Select-- by default...

    Any help please...

    Code:
    Try
                Using con As New SqlConnection("Data Source=DESKTOP-DGFWEGMJ;Initial Catalog=RCMS;Integrated Security=True")
                    DsPayments.EnforceConstraints = False
                    Me.VwpaymentsTableAdapter.Fill(Me.DsPayments.vwpayments, TxtPropertyIDClick.Text)
    
                    con.Open()
    
                    Dim dt As New DataTable()
                    Using cmd As New SqlCommand("Select rentmthID, MthYr from lkupmthrent", con)
                        Using adapter As New SqlDataAdapter(cmd)
                            adapter.Fill(dt)
                            With Details
                                .DisplayMember = "MthYr"
                                .ValueMember = "rentMthID"
                                .DataSource = dt
                            End With
                        End Using
                    End Using
    
                    con.Close()
                End Using
    
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
            End Try
    Thanks

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

    Re: Add --SELECT--

    Why would you want that? I see people ask for this often but it's quite silly. If the user can work out that they have to type something into a TextBox without you prompting them, why do you think that they can't work out that they have to select something in a ComboBox all on their own? What kind of morons are you expecting to use your application? Have they never used a computer before?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Re: Add --SELECT--

    Sorry for the confusion. It is a combo box with a dropdownlist, not a textbox.

    Thanks

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

    Re: Add --SELECT--

    Quote Originally Posted by dr225 View Post
    It is a combo box with a dropdownlist, not a textbox.
    I know it is. Did you actually read my post? Would you put a prompt in a TextBox to tell the user to type? Of course you wouldn't. In that case, why do you think you need to put a prompt in a ComboBox to tell the user to select? If someone is stupid enough to need that prompt, how did they turn the computer on in the first place?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Re: Add --SELECT--

    ...

    the form looks neat, do you have any other ideas?

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Add --SELECT--

    That's why CueTexts were "invented".
    To give a clue what a control is for or what it's purpose is.

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: Add --SELECT--

    It's a There will always be a better IDIOT
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Add --SELECT--

    Would a watermark work in this case? E.g.
    Code:
    Private Const CB_SETCUEBANNER As Integer = &H1703
    
    <DllImport("user32.dll", EntryPoint:="SendMessageW")> _
    Private Shared Function SendMessageW(hWnd As IntPtr, Msg As UInteger, wParam As UInteger, <MarshalAs(UnmanagedType.LPTStr)> lParam As String) As Integer
    End Function
    
    SendMessageW(Details.Handle, CB_SETCUEBANNER, 0, "--SELECT--")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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

    Re: Add --SELECT--

    Quote Originally Posted by dday9 View Post
    Would a watermark work in this case? E.g.
    Code:
    Private Const CB_SETCUEBANNER As Integer = &H1703
    
    <DllImport("user32.dll", EntryPoint:="SendMessageW")> _
    Private Shared Function SendMessageW(hWnd As IntPtr, Msg As UInteger, wParam As UInteger, <MarshalAs(UnmanagedType.LPTStr)> lParam As String) As Integer
    End Function
    
    SendMessageW(Details.Handle, CB_SETCUEBANNER, 0, "--SELECT--")
    That will work if the DropDownStyle is set to DropDown but not if it is DropDownList, which it probably ought to be. Again though, while the OP can do what they want, I have to ask why it would be considered a good idea to put a prompt in a ComboBox like that and not in a TextBox, as though one is so much harder to work out how to use than the other. Those cue banners should generally be used to indicate what the field is for, i.e. as an alternative to an adjacent descriptive Label.

  10. #10
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Add --SELECT--

    I would push back to that. For example, in web development it is common to use an "option label", e.g. https://docs.telerik.com/kendo-ui/ap...on/optionlabel -or- to set a telephone’s placeholder text to "(555) 555-5555". Albeit the second example does not necessarily apply to win form applications since we have the MaskedTextBox, I am pointing out that it is a common UI pattern that users are familiar with.

    In this case, you could insert a record at the top of the table with a null ID and have the DisplayValue to "--Select--" to get the desired behavior with a DropDownList style ComboBox. Then, if the field is required you would check if the SelectedValue is null and if it is then you would display an error, otherwise if it is not a required field then you would check if it is not null and if not then you would set the new record's value.

    My point is that it is much easier to program around expected behaviors than it is to retrain users.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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

    Re: Add --SELECT--

    Quote Originally Posted by dday9 View Post
    I would push back to that. For example, in web development it is common to use an "option label", e.g. https://docs.telerik.com/kendo-ui/ap...on/optionlabel -or- to set a telephone’s placeholder text to "(555) 555-5555".
    But you're not pushing back at all. In the examples you linked to, it is specifically saying "Select a fruit..." or "Select a product...", i.e. it's telling the user what the field is for, exactly as I said. It's not just saying "Select...", as though the user doesn't know that a drop-down is used for selection. I know that some people do just put "Select" in a drop-down but, yet again I ask, what is the justification for that when no one even considers putting a prompt to type into a text box? If people are really stupid or naïve enough to need a prompt to tell them what a drop-down is for, how are we trusting them to use the rest of the UI correctly? The fact is that this is really just a "because we can" feature. It serves no useful purpose. If that's what people want though, they can have it. If no one can provide a justification for doing this, it's clear that they don't care whether it's justified. I can only do so much so I'll leave it at that.

  12. #12
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Add --SELECT--

    That is just semantics. I am nothing saying that the OP couldn't provide a more descriptive cue, but you are (or rather were) saying he absolutely shouldn't add the cue to the collection at all.

    The common option label I personally use is "-". I think it looks better than an empty value and the users I help have come to expect it.

    So if the users expect a visual cue for null values, then by all means give it to them.

    @dr255 - if you are using a combo box then the placeholder text or cue text I showed you would suffice. If you are using a combobox as a DropDownList as jmcilhinney suggested, then take the other approach of inserting a null value record and check if the selected value is (or is not) null.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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

    Re: Add --SELECT--

    Quote Originally Posted by dday9 View Post
    That is just semantics.
    Nope.
    Quote Originally Posted by dday9 View Post
    I am nothing saying that the OP couldn't provide a more descriptive cue
    You didn't say they could/should either.
    Quote Originally Posted by dday9 View Post
    you are (or rather were) saying he absolutely shouldn't add the cue to the collection at all.
    What I'm actually saying is that they shouldn't add the prompt they asked to add. Post #9 should make it clear that I'm not against sensible/useful prompts.
    Quote Originally Posted by dday9 View Post
    The common option label I personally use is "-". I think it looks better than an empty value and the users I help have come to expect it.

    So if the users expect a visual cue for null values, then by all means give it to them.
    If that's what your users are used to in your applications then that's fine enough, but you have created that expectation. Again, why is an empty TextBox OK but an empty ComboBox isn't for some reason? Also, a prompt of "--Select--" is specifically an instruction, not just a placeholder for no data, so it's an extra layer of pointless.

  14. #14
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Add --SELECT--

    To be clear, I don't think that empty TextBox controls are visually pleasant either. I typically add a placeholder (aka cue), usually it mimics the label but not always.

    Is it an extra feature, yes. Is it pointless, that is subjective. You have made your point that you find it pointless.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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

    Re: Add --SELECT--

    Quote Originally Posted by dday9 View Post
    To be clear, I don't think that empty TextBox controls are visually pleasant either. I typically add a placeholder (aka cue), usually it mimics the label but not always.
    Then that is at least a consistent UI. If you don't like empty fields and wish to provide a prompt in all fields that would otherwise be empty, I can see the logic, even if it's not something I would do myself. My issue is when there is no logic, i.e. when an empty control of one type is not OK but of another type is for no apparent reason. My main issue is the inconsistency and the fact that most people who do this seem to do it just because they can without having any real justification for it.

  16. #16
    Lively Member
    Join Date
    Jun 2017
    Posts
    77

    Re: Add --SELECT--

    Really, the guy had a simple question and someone comes in and says don't use it. How is that helpful? My reply isn't helpful as well, but dear God some members here like to complicate things.

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

    Re: Add --SELECT--

    Quote Originally Posted by BlackRiver1987 View Post
    Really, the guy had a simple question and someone comes in and says don't use it. How is that helpful? My reply isn't helpful as well, but dear God some members here like to complicate things.
    If someone says "how can I do something I shouldn't do", it seems to me that the simplest response is "don't do it". Not quite sure how that's complicating things. Many people ask how to do things they shouldn't. Not informing them that they shouldn't is doing them a disservice. If they choose to do it anyway, that's then their informed choice.

  18. #18
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Add --SELECT--

    I've seen it done this way. I don't do it myself, but...whatever.
    My usual boring signature: Nothing

  19. #19
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Add --SELECT--

    Currently using the "-- Select --" not as a prompt, but because there are 3 choices in the dropdown, but 4 possible values - the three that are there and "NULL" ... by setting it to the select prompt, it indicates (when the thing works) that there isn't a current selection. Also allows the user to reset it back to NULL if needed. And it's not a required field.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Re: Add --SELECT--

    Thank you all - Much obliged

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Re: Add --SELECT--

    dday9 - thanks for the simple and straightforward answer. Grateful! Stay blessed...

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