Click to See Complete Forum and Search --> : Inserting text & value into combobox
nolc
May 27th, 2003, 11:37 AM
I am trying to insert "Select One" & value into a combobox on a Windows Form. I know how to do the insert with asp.net, but not in vb.net. Any thoughts?
asp.net:
cboVendors.Items.Insert(0, New System.Web.UI.WebControls.ListItem("All Vendors", "0"))
DSJ
May 27th, 2003, 02:48 PM
Same way....
ComboBox1.Items.Insert(0, "All Vendors")
nolc
May 28th, 2003, 08:51 AM
Yeah...I've tried that and I get this error, "Can't modify the Items collection when the DataSource property is set.".
Maybe I should have specified that I am also binding a dataset to the combobox. Please see my below code.
Public Sub LOADcboService()
Dim myDataSet As New DataSet()
Dim tmpTable As String = "Services"
myDataSet = GetDataSet(strConn, "spGETServiceList", tmpTable)
' CODE LOADS DATA INTO A COMBOBOX
cboService.DataSource = myDataSet.Tables(tmpTable)
cboService.ValueMember = myDataSet.Tables(tmpTable).Columns(0).Caption
cboService.DisplayMember = myDataSet.Tables(tmpTable).Columns(1).Caption
cboService.SelectAll()
ServiceID = CInt(cboService.SelectedValue.ToString)
'
cboService.Items.Insert(0, "Select one")
End Sub
nolc
May 28th, 2003, 10:00 AM
How about this... I was thinking I could pass the DataSet returned from the stored procedure and string to a Function which would then unpackage the DataSet into an Array with the String in the 0 position and then return the new DataSet. BUT this seems like a round about way of doing it...there's got to be an easier way???
Public Function Combo(sLabel as String, ds as DataSet) AS DataSet
|
'Array stuff
|
Return NewDS
End Function
nolc
May 30th, 2003, 11:21 AM
figured it out....
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.