Binding EasyObject to ComboBox??

Data Access Application Blocks Forum

Binding EasyObject to ComboBox??

Postby orsted on Thu Dec 08, 2005 9:59 pm

I am having a hell of a time doing this.

Here's teh code I *thought* would work:

Dim x As DA_CounselorEmails = New DA_CounselorEmails

With x
.DatabaseInstanceName = \"ICEMAN2\"
.LoadAll()
End With
With cmbCounselorList
.DataSource = x.DefaultView
.DisplayMember = x.CounselorName
End With



However - all i get when I run this is a combobox that contains System.Data.DataRowView as it's content (one item per item in the datatable - so it appears to be iterating through, but it's not putting the content of those CounselorName fields anywhere).

Furthermore - I tried the following code

With x
.Query.AddResultColumn(.CounselorName)
.Query.AddOrderBy(.CounselorName, NCI.EasyObjects.WhereParameter.Dir.ASC)
.Query.Load()
End With
With cmbCounselorList
.DataSource = x.DefaultView
.DisplayMember = x.CounselorName
End With


And I get an error every time that says
An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.

Additional information: Object reference not set to an instance of an object.


followed by a Msgbox that says \"There is no source code for the location\"..

So I can't really see where this thing is crashing on me.

Any advice/help?


Marko
orsted
Private First Class
 
Posts: 10
Joined: Wed Nov 23, 2005 8:12 pm

Postby mgnoonan on Fri Dec 09, 2005 1:49 am

This is a .NET issue, not an issue with EasyObjects, but you're oh so close, man... :wink:

The .DisplayMember is expecting the name of a column in the .DataSource, but you are trying to pass in an EO property value. So, if the current row of the EO has a CounselorName of \"Matt\", you have effectively coded this:

Code: Select all
cmbCounselorList.DisplayMember = \"Matt\"


Obviously, \"Matt\" is a value and not a column name. In addition, once the DataBinding starts, the value of CounselorName changes every time the row changes.

What you want is this:

Code: Select all
cmbCounselorList.DisplayMember = DA_CounselorEmailsSchema.CounselorName.FieldName


The FieldName property in the Schema class returns the actual column name in the database, which is also the column name in the DefaultView. You can also set the ValueMember in the same way (although I don't see you returning an ID field in your query).
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH

Postby orsted on Fri Dec 09, 2005 4:45 pm

Thanks much for the help. I really like the EasyObjects/DooDads stuff - just takes a lot of getting used to! :)..
orsted
Private First Class
 
Posts: 10
Joined: Wed Nov 23, 2005 8:12 pm

Postby mgnoonan on Fri Dec 09, 2005 4:56 pm

Believe me, once you do get used to it, your productivity will go way up and you'll wonder how you ever got by doing it the old way! 8)
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH


Return to EasyObjects.NET (Microsoft Enterprise Library)

Who is online

Users browsing this forum: No registered users and 2 guests

cron