zoukankan      html  css  js  c++  java
  • Winform下DataGridView评分单元格的痛苦折磨

    先上最终效果图:

    小小的一个功能折磨了哥近半个小时。

    首先是没有替换模板,新加一个列,然后妄想给这列的单元格赋值能达到效果,结果formattedValue和value都为空,好吧。我认了。

    直接给列的CellTemplate赋值,

    dataGridView1.Columns[2].CellTemplate = new DataGridViewTextBoxCellStar();

    然后出现了下列问题:

    是的,仔细一看,原本的数字还是存在的,只是上面几个有星星,把数字给遮住了,但是当有一个为0时,则会暴露出数字。

    首先想到了擦除,所以:

    graphics.FillRectangle(new SolidBrush(this.DataGridView.BackgroundColor), cellBounds);


    结果很悲剧:

    想来此this.DataGridView.BackgroundColor非彼DataGridView.BackgroundColor。

    突然想到一个偷懒的办法,设置文本的颜色。好吧。

    dataGridView1.Columns[2].DefaultCellStyle.ForeColor = dataGridView1.BackgroundColor;


    结果很好,但一点给暴露了:

    仔细对比这个图和第一、二个图,发现只有选择的时候,数字的颜色显示了出来。

    最后我怒了。真想写事件,切换文本颜色。但是觉得那样做太2了。

    结果,让我想到了最后的解决办法,也把我打击了一下。

    base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle, advancedBorderStyle, paintParts);


    是的,不让他画文字……

    我认为我很悲剧。

  • 相关阅读:
    动态传参
    函数的介绍
    文件的操作
    send email with formatted table
    minimize and close window with customed winform
    python algorithm
    something important about docker
    book list
    which language is suitable for what to do
    Find Duplicate Items in list fast
  • 原文地址:https://www.cnblogs.com/nanqi/p/DataGridView_Star.html
Copyright © 2011-2022 走看看