Hi,
I want to display a generic list of "Person" objects in an ultragrid.
My "Person" object contains properties for Name, Birthday, Address, and IsMarried.
I am able to set the Ultragrid's DataSource to a Generic List of Person objects. My problem is that the column headers are just the Property names. I'd like to be able to customize these names - for instance, IsMarried should really be shown to the user with a space in the name - "Is Married".
Is there some sort of attribute that i need to add to the properties, or another way of customizing these headers?
Thanks for the help,
~Karen
Hi Karen,
When you refer to a specific column like this, you should always use the key. The Index of a column may change, but the key probably won't.
So you would do something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; layout.Bands[1].Columns["Value"].Header.Caption = "Names"; }
Thanks Mike,
I will probably use option 2. But if I did want to use option 1, what is the best way for me to get to that column to change its header? Would there be unique keys, or would I just need to know the indexed positions of the columns?
Thanks,~Karen
I don't think it's possible to do this with a list of Strings, because you don't have the ability to add an attribute to the Value property of the string class.
So there are two ways you could change the column header text in the grid in this case.
1) Change the Caption on the grid column's header.
2) Don't use strings, but instead create a list of some other class that has a single property of type String. Then you can apply the DisplayName attribute to the property on your class.
I think I have partially found an answer...
If I import System.ComponentModel, I can then add a DisplayName attribute to my properties. For example,
<DisplayName("Is Married")> _Public Property IsMarried() As Boolean.....End Property
Now I have a new question. I want to add a Hobbies collection (Generic List of Strings) to my Person object. When I do this, I get a second band added to my grid like i would expect, however, the header is labeled "Values". Setting the DisplayName attribute on the Hobbies collection didn't work, I'm guessing because it's really the data inside of the collection that's being displayed. Could someone tell me how to get a custom header on this field?
Thanks,