|
-
Jun 27th, 2008, 04:12 AM
#1
Thread Starter
New Member
Bindinglist, custom columns
Hello,
I'm implementing a bindinglist, with a customObject.
If I bind the bindinglist to a grid, it works perfectly, but>>>
In my customobjects, i have relations to other customObjects, the grid shows those relations as a toString.
So in the grid I see the name of the customobject of the relation.
Is there a way, to show the colums of those related custom objects.
Example:
'A person object, with a age object, that contains the age of that person
Person
- name (String)
- Age (Age)
Age
- age (String)
If I add this to a bindinglist<T>, and bind this to a grid, it shows the name of the person, and the name of the age Class, and i want the value.
Is the only way, to add a property to the person object? Or is there an other way, so the bindinglist knows that subobjects, also need to be checked, en related to columns in de grid.
-
Jun 27th, 2008, 06:10 AM
#2
Re: Bindinglist, custom columns
When you bind Person objects to a grid the ToString method of each property value is called to get a string to display in the grid. By default a class's ToString method will simply return the class's name. If you don't want that then you have to override the ToString method of the Age class to return the value that you DO want displayed.
That said, what you've shown there is not a good example. I don't know if you're really using something like that but if you are I suggest that you change your design. In that situation there should be no Age class. The Person class should have a DateOfBirth property of type Date and you can then add an Age property that calculates the current age based on the current date and the date of birth. Binding such properties to a grid will inherently display the correct values. Maybe your types are different and that was just an example plucked out of the air. Regardless, it's somethig to consider.
-
Jun 27th, 2008, 06:26 AM
#3
Thread Starter
New Member
Re: Bindinglist, custom columns
 Originally Posted by jmcilhinney
When you bind Person objects to a grid the ToString method of each property value is called to get a string to display in the grid. By default a class's ToString method will simply return the class's name. If you don't want that then you have to override the ToString method of the Age class to return the value that you DO want displayed.
That said, what you've shown there is not a good example. I don't know if you're really using something like that but if you are I suggest that you change your design. In that situation there should be no Age class. The Person class should have a DateOfBirth property of type Date and you can then add an Age property that calculates the current age based on the current date and the date of birth. Binding such properties to a grid will inherently display the correct values. Maybe your types are different and that was just an example plucked out of the air. Regardless, it's somethig to consider.
Thanks for the answer.
First I would like to say, that the example with the person and age object, is not my design, but simple to show you what i mean.
Second of all, i know i can override the toString method, I already did that, but i what if the age object has 2 property's? How can i make it work, that when i bind the person object, the bindinglist knows that the age object, has 2 property's, so it creates to columns for it?
-
Jun 27th, 2008, 06:38 AM
#4
Re: Bindinglist, custom columns
 Originally Posted by Fantagon
How can i make it work, that when i bind the person object, the bindinglist knows that the age object, has 2 property's, so it creates to columns for it?
You can't.
-
Jun 27th, 2008, 06:48 AM
#5
Thread Starter
New Member
Re: Bindinglist, custom columns
 Originally Posted by jmcilhinney
You can't.
So, the best way, is to add a readonly property, that returns the age.age?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|