views:

38

answers:

2

I have a code:

VideoChannel[] channels = GetVideoChannels();

dataGridView1.DataSource = channels;
dataGridView1.Refresh();

VideoChannel is a class with many properties. This code works OK, but I want to change column names. By default, column name = property name of VideoChannel. Is there some attribute that I can mark a property of VideoChannel so column name != property name ?

A: 

Will this help you

dataGridView1.TableStyles[0].GridColumnStyles[0].HeaderText = "SomeDifferentColumnName"

or

dataGridView1.Columns[0].HeaderText = "SomeDifferentColumnName"

Source: http://stackoverflow.com/questions/125719/datagridview-edit-column-names

Source in turn: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/8b9b07d4-06fc-4c12-9509-0c19ca04e003/

Veer
In that option, I must manually assign header text to columns. I don't like this solution. Maybe, there is some attribute that I can use with videochannel properties ?
alex
A: 

You can change column name in design mode where you create column and set it's properties. Or you can try

DataGridName.Colimns[0].HeaderText = "Your Header0";
DataGridName.Colimns[1].HeaderText = "Your Header1";
.
.
.
DataGridName.Colimns[N].HeaderText = "Your HeaderN";

But the better way is to do this in design mode.

Johnny
I know how to set column name programmatically, I asked about if I can set it automatically using some attributes in binding class.
alex
Yes you can do that. oops by the way which one r u using wpf or winforms .? If you r using wpf then u can set bind the header text of datagrid column with 1 of the property of VideoChannel class
Johnny
WinForms.That solution doesn't fit me. I don't want to set header text manually - i want it will be automatically using attributes of my custom structure fields.
alex