-
May 24th, 2022, 08:05 AM
#1
Thread Starter
Lively Member
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
-
May 24th, 2022, 08:12 AM
#2
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?
-
May 24th, 2022, 08:18 AM
#3
Thread Starter
Lively Member
Re: Add --SELECT--
Sorry for the confusion. It is a combo box with a dropdownlist, not a textbox.
Thanks
-
May 24th, 2022, 08:23 AM
#4
Re: Add --SELECT--
Originally Posted by dr225
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?
-
May 24th, 2022, 08:26 AM
#5
Thread Starter
Lively Member
Re: Add --SELECT--
...
the form looks neat, do you have any other ideas?
-
May 24th, 2022, 08:31 AM
#6
Re: Add --SELECT--
That's why CueTexts were "invented".
To give a clue what a control is for or what it's purpose is.
-
May 24th, 2022, 10:36 AM
#7
Re: Add --SELECT--
It's a There will always be a better IDIOT
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 24th, 2022, 03:34 PM
#8
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--")
-
May 24th, 2022, 08:34 PM
#9
Re: Add --SELECT--
Originally Posted by dday9
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.
-
May 24th, 2022, 09:32 PM
#10
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.
-
May 24th, 2022, 09:52 PM
#11
Re: Add --SELECT--
Originally Posted by dday9
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.
-
May 24th, 2022, 10:10 PM
#12
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.
-
May 24th, 2022, 10:33 PM
#13
Re: Add --SELECT--
Originally Posted by dday9
That is just semantics.
Nope.
Originally Posted by dday9
I am nothing saying that the OP couldn't provide a more descriptive cue
You didn't say they could/should either.
Originally Posted by dday9
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.
Originally Posted by dday9
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.
-
May 24th, 2022, 10:49 PM
#14
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.
-
May 24th, 2022, 10:58 PM
#15
Re: Add --SELECT--
Originally Posted by dday9
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.
-
May 25th, 2022, 02:43 AM
#16
Lively Member
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.
-
May 25th, 2022, 03:33 AM
#17
Re: Add --SELECT--
Originally Posted by BlackRiver1987
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.
-
May 26th, 2022, 12:13 PM
#18
Re: Add --SELECT--
I've seen it done this way. I don't do it myself, but...whatever.
My usual boring signature: Nothing
-
May 26th, 2022, 12:41 PM
#19
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
-
May 27th, 2022, 07:10 AM
#20
Thread Starter
Lively Member
Re: Add --SELECT--
Thank you all - Much obliged
-
May 27th, 2022, 07:12 AM
#21
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|