By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,696 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,696 IT Pros & Developers. It's quick & easy.

Adding blank line to combo box using Generics and BindingSource VB 2005

P: n/a
I've got a combo box that I want to bind a collection to. I got the
error "Complex Data Binding accepts as a data source either an IList or
an IListSource" so I tried using the BindingSource, which works except
when I want to have a blank line as the first item in the combo
box--then all that is displayed is the type of object.

Here is the code for filling the collection:

Public Function GetCollection(ByRef cndb As SqlConnection, Optional
ByVal addBlank As Boolean = True, Optional ByVal activeOnly As Boolean
= True) As SingleKeyCollection(Of KeyType, ObjectType)
Try
'Wrap the collection in the wrapper to properly load from
XML
Dim coll As New CollectionWrapper(Of KeyType, ObjectType)
'Be sure to convert all strings to db type paramaters using
db.todb()
coll = db.executeCollectionReader(cndb,
db.buildCommand(cndb, SP_GETS, PARAM_ACTONLY, activeOnly), coll)

If IsNothing(coll) Then
coll = New CollectionWrapper(Of KeyType, ObjectType)
End If
'If addBlank is true add a null ent
If addBlank Then

Dim blank As ObjectType =
Activator.CreateInstance(GetType(ObjectType))
With blank
.SetKey(CType(NULL_KEY_VALUE, KeyType))
.IsActive = True
.IsActiveSpecified = True
End With
'add the blank to the front of the collection
If coll.Items.Count = 0 Then
coll.Items.Add(blank)
Else
coll.Items.Insert(0, blank)
End If
End If

'return the collection
Return coll.Items

Catch ex As SQL_GerneralException
Throw New BL_SQLException(ex.Message)
Catch ex As SQL_UnknownSQLException
Throw New BL_SQLException(ex.Message)
Catch ex As Exception
Throw New BL_GeneralException(ex.Message)
End Try
End Function

Here is the code where I'm trying to fill the combo box:

Public Overridable Sub SetDropDowns(ByVal groupTitleCollection As
SingleKeyCollection(Of Integer, ContactGroupTitle_BO))
Dim bindingsource1 As New BindingSource

'Set the grouptitle datasource
'Me.cboGroupTitle.DisplayMember = "DisplayValue"
'Me.cboGroupTitle.ValueMember = "Key"
bindingsource1.DataSource = groupTitleCollection
Me.cboGroupTitle.DisplayMember = "DisplayValue"
Me.cboGroupTitle.ValueMember = "Key"
cboGroupTitle.DataSource = bindingsource1

End Sub

Now when I call the GetFunction to create a collection and I pass in
false for the optional parameter addBlank, the values I expect to be
displayed in the combo box are displayed but I want a blank line as
users don't always want to select a value and when I pass in true for
the optional parameter, then the type of groupTitleCollection is
displayed (and in this example, it's
BusinessLogic.ContractGroupTitle_BO. Any suggestions of what needs to
be changed?

Thanks.

Molly J. Fagan

Sep 18 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.