Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Text to DataGridView Row Header

Does C# allow you to add a String to a RowHeader in a DataGridView? If so, how is it accomplished?

I'm writing a Windows Form to displayed Customer Payment Data for the year so far.

The ColumnHeaders display January, February, March, etc... and rather than have a blank column with DateTime.Now.Year I would like to put it in the RowHeader to make it stand out from the actual payment data.

like image 287
Bailz Avatar asked Sep 06 '25 14:09

Bailz


2 Answers

private void dtgworkingdays_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    this.FillRecordNo();
}


private void FillRecordNo()
{
    for (int i = 0; i < this.dtworkingdays.Rows.Count; i++)
    {
        this.dtgworkingdays.Rows[i].HeaderCell.Value = (i + 1).ToString();
    }
}

Also see Show row number in row header of a DataGridView.

like image 113
Moon Avatar answered Sep 08 '25 03:09

Moon


datagridview1.Rows[0].HeaderCell.Value = "Your text";

It works.

like image 41
Monali Avatar answered Sep 08 '25 02:09

Monali