Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2004

Tip: Looking for answers? Try searching our database.

ComboBox Datasource problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edgardo - 22 Jun 2004 19:23 GMT
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
Claes Bergefall - 23 Jun 2004 15:00 GMT
Your Account class is missing the Name and Amount
properties that you're trying to use

   /claes

> 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
[quoted text clipped - 36 lines]
>
> Thanks for your time

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.