|
-
Nov 7th, 2011, 11:04 AM
#1
Thread Starter
Addicted Member
Combobox initial value
I am using a form with a combobox which is populated from an SQL database table. This works OK but is it possible to leave the box blank on the form until a value is selected.By default the box has the content of the first record.
-
Nov 7th, 2011, 11:15 AM
#2
Re: Combobox initial value
yes it is possible , provided your combobox dropdownstyle property is set to dropdown or simple
if it is set to dropdownlist it is not possible
vb Code:
With Me.ComboBox1 .DropDownStyle = ComboBoxStyle.DropDown .Text = "" End With
-
Nov 7th, 2011, 11:46 AM
#3
Thread Starter
Addicted Member
Re: Combobox initial value
'CRAP'
Not the answer I wanted to see but it happens.
At least I now know how to do it but I also wanted to prevent the end user from making any changes so I had a dropdownlist. Thanks for your reply.
-
Nov 7th, 2011, 12:50 PM
#4
Re: Combobox initial value
combobox dropdownlist property is not the ultimate to restrict the users from entering their own choice
use this function in combobox lostfocus event, which will tell whether the user has chosen the corrent value or else entered his own text
vb Code:
Private Function LocokComboForEdit() As Boolean 'locks the combobox for edit If Me.ComboBox1.Text = "" Then Exit Function Dim Sel_Item_index As Integer = Me.ComboBox1.SelectedIndex If Sel_Item_index < 0 Then MessageBox.Show("Invalid entry ") Else MessageBox.Show("DCorrect entry") End If End Function
use the return values of this function as per your connivance.
-
Nov 8th, 2011, 11:29 AM
#5
Junior Member
Re: Combobox initial value
Hi.
You can also try this other method while using the dropdownstyle as dropdownlist.
1. At the form load, query your database for the values you want to fill the combobox with, and fill it through a loop
2. Before you fill the combobox with the values, add a blank one i.e. ( combobox1.items.add("") )
3. After a user selects a value from the combobox, delete the first one, which will be the blank one, something like this :
VB Code:
private sub combobox1_selectedindexchanged()
if combobox1.items(0) = "" then
combobox1.items.removeat(0)
end if
end sub
That way the combobox will have a blank value untill the user selects one, while restricting the user from inputting his own values.
Tags for this Thread
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
|