Reputation: 3790
Im trying to Programaticly change the DataGridViews
"Cell Header" font style
The Col headers have to be UpperCase and I want to assign a new font.
If someone has done this before I would appreciate your guidance here.
Actually the font changing works fine its just the headerText.ToUpper()
I need help with
private void dataGridView1_Painting(object sender, DataGridViewCellPaintingEventArgs e)
{
//Something like this.
foreach(DataGridViewColumnCollection c in grd.Columns) {
c.ColHeading.Text = c.ColHeading.Text.ToUpper();
}
//or
//header row only
if (e.RowIndex == -1)
{
e.CellStyle.Font = new Font("Verdana", 11.0f);
e.CellStyle.ForeColor = Color.Gray;
e.Value = e.Value.ToUpper(); //fails as its a read only object
}
}
Upvotes: 0
Views: 361
Reputation: 38365
Not familiar with this control, but browse other events. May not be making this change early enough, and have better luck with an "earlier" event.
There may be events on the rows or columns themselves that you should be wiring up to to accomplish this.
IEnumerable's solution as per comment:
dataGridView1_ColumnAdded(object sender, DataGridViewColumnEventArgs e) { e.Column.HeaderText = e.Column.HeaderText.ToUpper(); }
Upvotes: 1