Dynamicaly将字体设置为DatagridView的单元格

Nit*_*esh 2 .net datagridview winforms

在我winform使用DataGgridView 在某些情况下,我想将特殊字体设置为某些列,我使用以下代码实现

this.grvInvoice.Columns["mat_Name"].DefaultCellStyle.Font = new Font("Verdana", 14);
Run Code Online (Sandbox Code Playgroud)

但我想只为某些单元格设置某些字体和大小.我尝试以下代码

grvRequest.Rows[i].Cells["item"].Style.Font = new Font("Verdana", 14);
Run Code Online (Sandbox Code Playgroud)

不行不通.是否有可能set specific font and size dynamically to a cell of DataGridView

Dmi*_*lov 5

您可以使用以下代码为每个单元格设置单独的样式:

DataGridViewCell cell=null;
// Get a cell you need here
cell.Style = new DataGridViewCellStyle()
{
        BackColor = Color.White,
        Font = new Font("Tahoma", 8F),
        ForeColor = SystemColors.WindowText,
        SelectionBackColor = Color.Red,
        SelectionForeColor = SystemColors.HighlightText
};
Run Code Online (Sandbox Code Playgroud)

但是,如果您看不到任何可能意味着您在父级别设置了某种样式的结果,并且该样式会覆盖您的样式.

有关更多信息,请查看本文的样式继承:Windows窗体DataGridView控件中的单元格样式.