|
-
Nov 11th, 2007, 06:12 PM
#1
Thread Starter
Junior Member
How To : Blank Line at Top of Combobox
I am using the following code to populate a combobox whose SelectedValue property is used to build part of an SQL string to do a lookup in a table.
'Get Everything in a Dataset Object
objData.SQL = "SELECT ConsignorID, ConsignorName FROM Consignors"
objConsignorDS = New DataSet
Call objData.FillDataSet(objConsignorDS, "Consignors")
dtConsignors = objConsignorDS.Tables(0)
'Bind the Consignors ComboBox
cboConsignor.DataSource = objConsignorDS.Tables("Consignors")
cboConsignor.DisplayMember = "ConsignorName"
cboConsignor.ValueMember = "ConsignorID"
The issue I have is that I am stuck with always having one Combobox item displayed, so the SQL statement cant be used currently to select "ALL" .
I need to find out how to setup the combobox with an "ALL" as one of the selections given the method being used above. If I need to change it, then I will do that.
Thanks in advance.
-
Nov 11th, 2007, 06:18 PM
#2
Re: How To : Blank Line at Top of Combobox
No, you're not always stuck with one of the selections showing. The answer to this question is the same as all the other times it's been asked: set the SelectedIndex to -1 and no item will be selected.
When you bind a ComboBox to a data source the control will display all the items in the data source and only the items in the data source. If you want to add an extra item then you have two choices:
1. Add the extra item to the data source.
2. Don't bind the control, but rather add the items manually.
-
Nov 13th, 2007, 12:05 AM
#3
Thread Starter
Junior Member
Re: How To : Blank Line at Top of Combobox
That is what I was afraid of.
One question .... What if you manually added the "All" and then used a DataReader with a loop to complete the fill ?
-
Nov 13th, 2007, 12:13 AM
#4
Re: How To : Blank Line at Top of Combobox
I already addressed that:
If you want to add an extra item then you have two choices:
1. Add the extra item to the data source.
2. Don't bind the control, but rather add the items manually.
-
Nov 13th, 2007, 07:08 AM
#5
Addicted Member
Re: How To : Blank Line at Top of Combobox
Adding the extra items to the Data source and setting the SelectedProperty to -1 would be the better option
Thanks
-
Nov 19th, 2007, 01:37 AM
#6
Junior Member
Re: How To : Blank Line at Top of Combobox
You probably need to change your sql query to the following query. This will do what you try to accomplish.
objData.SQL = "SELECT '' AS ConsignorID, 'ALL' as ConsignorName UNION ALL SELECT ConsignorID, ConsignorName FROM Consignors"
-
Dec 7th, 2007, 04:08 AM
#7
Fanatic Member
Re: How To : Blank Line at Top of Combobox
sorry for jumping in here guys..
I kind of have the same problem.
Lets save my combobox is bound and textboxes in turn are bound to that when a selection is made.
How can i add in like <Please select> which will keep my textboxes blank..
I have tried the selected index but my textboxes still fill to the first item in the combobox
if you catch my drift
-----------------------------------------------------------
Okay i have added a new record to the Datasource
Problem is it appears at the bottom of the list
lol
keep you guys posted
I am adding it to the datasource then im binding it
Last edited by d2005; Dec 7th, 2007 at 04:53 AM.
it works 60% of the time, all the time.
-
Dec 7th, 2007, 06:27 AM
#8
Fanatic Member
Re: How To : Blank Line at Top of Combobox
Hi guys,
heres the latest.. little help needed
i have changed the selected index and if selected index is -1 then clearing my textboxes ... works fine
next part is clearing all again when they press delete
works fine ( searched forums )
but i also
do not want them to be able to type into the combo box
Select Case e.KeyCode
Case Keys.Delete, Keys.Back
Me.mycombo.SelectedIndex = -1
'Case Else
' e.keycode = nothing - not allowing the user to type into my combo
End Select
any ideas greatly appreciated
-----------------------------------------
actually its probably best if i could say
if its not on my list then clear
Last edited by d2005; Dec 7th, 2007 at 06:51 AM.
it works 60% of the time, all the time.
-
Dec 10th, 2007, 04:18 AM
#9
Fanatic Member
Re: How To : Blank Line at Top of Combobox
 Originally Posted by d2005
actually its probably best if i could say
if its not on my list then clear
I am trying this on the leave event of the combo..
it seems to always clear??
Code:
If Me.myCombo.Text > "" And Me.myCombo.SelectedText = "" Then
MessageBox.Show("Please select a valid record")
Me.myCombo.SelectedIndex = -1
myCombo.Focus()
End If
it works 60% of the time, all the time.
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
|