从DataGridView更新所有单元格的样式 [英] Update style for all cells from DataGridView

查看:106
本文介绍了从DataGridView更新所有单元格的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从DataGridView中更新所有单元格的样式,无需像下面的例子那样迭代?

Is it possible to update style for all cells from DataGridView without iteration over them like example below?

for (int i = 0; i < dgv.Columns.Count; i++)
    for (int j = 0; j < dgv.Rows.Count; j++)
        if (dgv[i, j].Style != style)
            dgv[i, j].Style = style;

我的问题是一个实际的,因为所有单元格的更新速度都很慢。

My question is an actual due to slow speed of slyle updating for all cells.

推荐答案

如果要对所有单元格应用相同的样式,只需使用 DefaultCellStyle 的datagridview。

If you want to apply the same style to all the cells, simply use the DefaultCellStyle of the datagridview.

dataGridView.DefaultCellStyle.BackColor = Color.Green;

当您要将不同的样式应用于同一行中的不同单元格时,Killercam的答案将会很有帮助。

The answer of Killercam would be helpful when you want to apply different styles to different cells on the same rows.

这篇关于从DataGridView更新所有单元格的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆