c# - 如何绘制 DataGridViewComboBox 列中的非事件行?

标签 c# .net winforms custom-controls datagridviewcombobox

我可以easily paint items in DataGridViewComboBox dropdown list .但我无法弄清楚如何在同一列中绘制非事件单元格

Example of DataGridViewComboBox

我看过、研究过并尝试过许多经典的例子 ComboBox ,但我不了解DataGridViewComboBox的所有方面.

目前我有从 DataGridViewComboBox 派生的 DataGridViewCustomPaintComboBox 类。提供的最小覆盖集是多少?你能给我指出正确的方向吗?

最佳答案

在没有焦点的情况下绘制非事件单元格所需的最小值似乎是CellTemplate 赋值和Paint() 覆盖:

public class DataGridViewCustomPaintComboBox : DataGridViewComboBoxColumn
{

    public DataGridViewCustomPaintComboBox()
    {
        base.New();
        CellTemplate = new DataGridViewCustomPaintComboBoxCell();
    }

}

public class DataGridViewCustomPaintComboBoxCell : DataGridViewComboBoxCell
{

    protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
    {
        // modify received arguments here
        base.Paint(...); // paint default parts (see paintParts argument)
        // add any custom painting here

    }

}

关于c# - 如何绘制 DataGridViewComboBox 列中的非事件行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31452931/

相关文章:

c# - GPS定位API?

c# - 配置 .NET WCF UTF-8 反序列化器以修改/丢弃非最短格式字符而不是抛出异常?

c# - 为什么 List<> 实现 IList

javascript - 从 MVC 下载文件

c# - 检测表单关闭的原因

c# - 如何在C# winforms控件上嵌入Java控件?

c# - 如何在 C# 中生成一个随机命名的文本文件?

c# - 无法加载文件或程序集 'Office, Version=15.0.0.0'

c# - 如何在 .Net for Mac 中使用 appSettings

c# - 如何使用 C# 淡入/淡出包含内容的面板