C# 将字体更改为DataGridView行在WinC窗体中不起作用#

C# 将字体更改为DataGridView行在WinC窗体中不起作用#,c#,winforms,datagridview,C#,Winforms,Datagridview,我有管理datagridview对象的方法: internal static void LoadChannelsInGrid(DataGridView dg, Label noDataLbl, string feedUrl) { var response = RssManager.GetRss(feedUrl); if (response != null) { noDataLbl.Visible = false; dg.Visible =

我有管理datagridview对象的方法:

internal static void LoadChannelsInGrid(DataGridView dg, Label noDataLbl, string feedUrl)
{
    var response = RssManager.GetRss(feedUrl);
    if (response != null)
    {
        noDataLbl.Visible = false;
        dg.Visible = true;
        var items = response.OrderByDescending(s => s.PubDateUnix);
        dg.DataSource = items.ToArray();

        FontifyDataGrid(dg);
    }
    else
    {
        noDataLbl.Visible = true;
        dg.Visible = false;
    }
}

似乎行(模型项满足
IsLoaded
value)没有粗体样式,仍然看起来很规则


为什么?

如果我理解正确,当IsLoaded属性为true时,需要将字体设置为粗体


在这种情况下,您需要在RowPostPaint事件中将
if(!item.IsLoaded)
更新为
if(item.IsLoaded)

,请尝试以下操作:
if(!((dg.Rows[e.RowIndex].DataBoundItem as ChannelData){dg.Rows[e.columndex].DefaultCellStyle.Font=[newFont];}
。您应该将该字体存储在某个位置,这样您就不必每次都
new
。当条件发生变化时,您似乎不想用其他内容替换它。您对构造函数中
DataGridView
的单元格和行所做的更改(在form Load事件之前)将不会持久化,并且将丢失。不仅仅是样式,而是行和单元格的所有更改。是这样吗?同样,正如Jimi已经提到的,一般来说,您可能需要考虑使用Cys/Read事件,例如“代码> CytoFrimeT/<代码>,<代码> RooPrPosie,…
private static void FontifyDataGrid(DataGridView dg)
{
    for (var i = 0; i < dg.Rows.Count; i++)
    {
        var item = dg.Rows[i].DataBoundItem as ChannelData;
        if (item == null)
        {
            continue;
        }

        if (!item.IsLoaded)
        {
            var actualFont = new Font("Microsoft Sans Serif", 7.8f, FontStyle.Bold);
            dg.Rows[i].DefaultCellStyle.Font = actualFont;
        }
    }
}
LoadChannelsInGrid(dataGridView1, noDataLbl, "https://....");