简体   繁体   中英

Change text color of cells in Account column (C# datagridview)

I'm trying to change the font color of all rows in the Account column on program load with little success. Am I doing anything wrong here?

This is my code so far:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Account")
    {
        e.CellStyle.ForeColor = Color.Blue;
    }
}

这个这个(它将用蓝色为这一行文本着色):

this.dataGridView1.Columns["Account"].DefaultCellStyle.ForeColor = Color.Blue;

只需添加以下行:

this.previousRentDataGridViewTextBoxColumn.ItemStyle-ForeColor = <color>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM