开发者

how to change color of a column in datagridview?

开发者 https://www.devze.com 2023-04-06 01:23 出处:网络
I have a DataGridview, and I\'m settin开发者_如何学编程g some of the columns to readonly for data entry purposes.When I do that, the column stays the normal white (although it does not allow entry).Ho

I have a DataGridview, and I'm settin开发者_如何学编程g some of the columns to readonly for data entry purposes. When I do that, the column stays the normal white (although it does not allow entry). How can I color the column gray? I've seen lots of samples on how to color rows, but not columns.

How can I make the readonly columns look gray?


Try setting the DefaultCellStyle property for the selected columns.

Edit:

grid.Columns["NameOfColumn"].DefaultCellStyle.ForeColor = Color.Gray;


just change the style for the DataGridViewColumn object,

myGrid.Columns["myColumn"].DefaultCellStyle.BackColor = Color.Red;


You can specify the cell background colours for a column like so using the DefaultCellStyle property of a DataGridViewColumn.

DataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Gray;


        DataGridViewColumn firstColumn = dataGridView.Columns[0];
        DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
        cellStyle.BackColor = Color.Grey;

        firstColumn.DefaultCellStyle = cellStyle;
0

精彩评论

暂无评论...
验证码 换一张
取 消