簡體   English   中英

根據列名稱更改列中行中文本的所有顏色(datagrid)

[英]Change all the colours of text in rows in a column depending on the column name (datagrid)

我想根據C#中的列名更改列中行的所有文本顏色。 我怎么做到這一點?

到目前為止,我已經嘗試了以下內容:

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

該程序構建 - 但它根本不起作用

如果你想改變特定的colum forecolor,那么使用這個,

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

你可以使用一個switch

        switch (dataGridView1.Columns[e.ColumnIndex].Name)
        {
            case "DatePaid":
                dataGridView1.Columns[e.ColumnIndex].DefaultCellStyle.ForeColor = Color.Blue;
                break;
            case "Something":
                dataGridView1.Columns[e.ColumnIndex].DefaultCellStyle.ForeColor = Color.Red;
                break;
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM