Why not create a list of CQQ and then bind the combobox to it. Then to add
anything to the combobox, you'll have to add it to the list, which will
blow up if you try to add an object other than a CQQ to it. Off the top of
my head, something like this:
Dim myList As List(Of CQQ)
'add entries to the list
myList.Add(New CQQ("field1", "field2"))
myList.Add(New CQQ("field1", "field2"))
myList.Add(New CQQ("field1", "field2"))
myComboBox.DataSource = myList
myComboBox.DisplayMember = myList.field2
myComboBox.ValueMember = myList.field1
Robin S.
------------------------------------------
" active" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm using a ComboBox to display objects of a class I've defined, say CQQ.
>
> Works great except somehow I occasionally set an Item to a String object
> instead of an object of type CQQ.
>
> It looks like Text replaces an item or something like that.
>
> This results in a runtime error at which time I learn that the item that
> should be CQQ is a String.
>
> I can't find out where or how the setting happens.
>
> It occurs to me that if the comboBox defined it's Items as objects of
> type CQQ instead of Object it would the usage would be less error prone
> and more likely to be bug free.
>
> Is there some way I could generate a strongly typed combobox?
>
> I know I could simply inherit a combobox and try to override anything the
> changes an Item but that leaves the possibility that I'd miss some method
> and not really have what I want. I'd like to just change the Items
> collection once.
>
> Is that possible?
>
>
> Thanks
>
>
>
|