ComboBox Datasource problem

E

Edgardo

Hi, i am having a little problem with a combobox that i set his datasource
property to a collection, but doesn populate its items, the strange thing is
that i do the same thing on a datagrid and it works fine.

Take a look:


Public Class Account
Public Sub New(ByVal txtname As String, ByVal txtamount As Double)
name = txtname
amount = txtamount
End Sub
End Class

****************************************

Dim Accounts As New Collection()
Dim NewAccount As New Account("numer1", 1000)
Accounts .Add(NewAccount , 1)
Dim AnotherAccount As New Account("numer2", 2000)
Accounts .Add(AnotherAccount , 2)

*******************************************
Me.ComboBox.DataSource = Nothing
Me.ComboBox.DataSource = Accounts
Me.ComboBox.DisplayMember = "Name"
Me.ComboBox.ValueMember = "Amount" -----Error

"An unhandled exeception of type 'System.InvalidCastException ocurred in
microsoft.visualbasic.dll
Cast from type 'Microsoft.VisualBasic.Collection' to type 'Object()' is not
valid'"

Any ideas?

why i can set the same datasource for a datagrid and the is no error
showing? am i manipulating wrong the collection?

Any suggestion will help.

Thanks for your time
 
C

Claes Bergefall

Your Account class is missing the Name and Amount
properties that you're trying to use

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top