Databinding With Objects

P

Patrick

I've been struggling with a while. Could someone please help me out?
I need to bind a property (wich is an custom object)
to a combobox that contains a list of the same objects.

ex:
class Manager()
{
public Employee EmployeeInfo
}

combobox contains a collection of Employee objects.
When navigating, I would like to autimatically display a field from the
corresponding Employee object from the combo that matches what is assigned
to the Manager. As well as be able to change the Managers Employee object to
what is selected in the combobox.

Everything works fine when I change the Employee object of the Manager to
say... EmployeeID (Which is a string).

Thanks a whole million!
--PAtrick
 
A

aaron.kempf

C# does not support databases; they shoved XML and OOP so far down our
throats; I haven't made it to databases yet.. It's like databases are
an afterthough for C#



(NO WONDER ORACLE IS CLEANING MICROSOFTS CLOCK)
 
R

RobinS

Patrick said:
I've been struggling with a while. Could someone please help me out?
I need to bind a property (wich is an custom object)
to a combobox that contains a list of the same objects.

ex:
class Manager()
{
public Employee EmployeeInfo
}

combobox contains a collection of Employee objects.
When navigating, I would like to autimatically display a field from the
corresponding Employee object from the combo that matches what is
assigned to the Manager. As well as be able to change the Managers
Employee object to what is selected in the combobox.

Everything works fine when I change the Employee object of the Manager to
say... EmployeeID (Which is a string).

Thanks a whole million!
--PAtrick

Are you saying this: you are navigating through a list of Managers. Manager
has a property called Employee. Somewhere else there is a list of
Employees.

You want to bind the combobox so it saves the EmployeeID in the Manager
object, but shows the entries from the Employee list as options to be
selected?

You want to bind the combobox to the Employee list, then bind the
SelectedValue to the EmployeeID in the Manager object.

myComboBox.DataSource = EmployeeList
myComboBox.DisplayMember = EmployeeList.EmployeeName
myComboBox.ValueMember = EmployeeList.EmployeeID
myComboBox.SelectedValue = ManagerList.EmployeeID

Oh, and ignore that post from AaronKempf; he's trolling.

Good luck, and if I didn't get the gist of your problem, please post again.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
P

pfc_sadr

if you want to just bind, set the recordsource of your form and your
controlsource on the control

OH, WAIT A SECOND, CSHARP DOES NOT KNOW ANYTHING ABOUT DATABASES
 
P

Patrick

Thanks Robin, that was very helpful and exactly what I was looking for.
Thanks again.
Patrick
 
R

RobinS

You're welcome. By the way, there's a new book out called "Doing Objects in
VB2005" by Deborah Kurata that has a decent example of writing an
application using the 3-layer model. I know it's in VB, but that's not too
far from C#. She shows how to do data binding in the Designer with business
objects. Pretty cool. Just FYI.

Robin S.
-------------------------
 

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