首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改RowIndex 0上的DataGridviewCellStyle

更改RowIndex 0上的DataGridviewCellStyle
EN

Stack Overflow用户
提问于 2016-09-22 22:20:29
回答 1查看 30关注 0票数 0

我使用以下代码来更改datagridview的CellEnter事件中的单元格样式。但是,如果我删除if语句,在绑定数据后,所有行都将格式化为粗体。有什么建议或建议吗?

代码语言:javascript
复制
DataGridViewCellStyle oStyle = new DataGridViewCellStyle();
            oStyle.Font = new Font("Microsoft Sans Serif", 9.25f, FontStyle.Bold);

            if (e.RowIndex > 0)
            {
                dataGridView1.Rows[e.RowIndex].Cells[0].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[1].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[2].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[3].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[4].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[5].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[6].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[7].Style = oStyle;
                dataGridView1.Rows[e.RowIndex].Cells[8].Style = oStyle;
            }
EN

回答 1

Stack Overflow用户

发布于 2016-09-22 22:53:21

如果我没理解错的话,那就是你所期望的行为。您可以尝试将上述代码添加到CellMouseClick事件中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39641644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档