Reputation: 1149
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 ?
Upvotes: 5
Views: 5616
Reputation: 10306
You may want to try DisplayName
Attribute. Decorate your class property with it.
public class SomeItem
{
[DisplayName("SomeItem")]
public string Name { get; set; }
}
Upvotes: 12
Reputation: 1575
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.
Upvotes: 1
Reputation: 12934
Will this help you
dataGridView1.TableStyles[0].GridColumnStyles[0].HeaderText = "SomeDifferentColumnName"
or
dataGridView1.Columns[0].HeaderText = "SomeDifferentColumnName"
Source: DataGridView Edit Column Names
Source in turn: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/8b9b07d4-06fc-4c12-9509-0c19ca04e003/
Upvotes: 0