Set background color only for the first row in a DataGrid?

痴心易碎 提交于 2019-12-25 18:25:22

问题


I'm trying to change the color only for the first color of a DataGrid in a smartDevice project in c#. I tried to use the "Paint" event but couldn't figure out if it could solve my issue. I'm using Microsoft Visual Studio 2008.

This is a testing code

private void buttonRed_Click(object sender, EventArgs e)
    {
        DataRow row = this.dataSet1.Tables[0].NewRow();
        row[0] = "002";
        row[1] = "E";
        this.dataSet1.Tables[0].Rows.InsertAt(row, 0);
    }
    private void load()
    {

        this.dataSet1.Tables[0].Rows.Add(new object[] { "001", "A" });
        this.dataSet1.Tables[0].Rows.Add(new object[] { "002", "B" });
        this.dataSet1.Tables[0].Rows.Add(new object[] { "001", "C" });
        this.dataSet1.Tables[0].Rows.Add(new object[] { "003", "D" });
    }
    private void buttonGreen_Click(object sender, EventArgs e)
    {
        DataRow row = this.dataSet1.Tables[0].NewRow();
        row[0] = "004";
        row[1] = "F";
        this.dataSet1.Tables[0].Rows.InsertAt(row, 0);
    }

回答1:


dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Azure;

Just do this will work... 0 means the first row.



来源:https://stackoverflow.com/questions/23753299/set-background-color-only-for-the-first-row-in-a-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!