Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 如何创建带有浮动标签的自定义DataGridViewComboxCell_Winforms_Custom Controls_Datagridviewcombobox - Fatal编程技术网

Winforms 如何创建带有浮动标签的自定义DataGridViewComboxCell

Winforms 如何创建带有浮动标签的自定义DataGridViewComboxCell,winforms,custom-controls,datagridviewcombobox,Winforms,Custom Controls,Datagridviewcombobox,我希望在同一datagridview列中有两个控件 我想自定义DataGridViewComboxCell,这样它将显示所选值的值,并在其上显示带有一些文本的浮动标签。在过去,我可以通过复选框和标签来实现这一点,但DataGridViewComboxCell的问题是,当我重写paint事件时,它会显示一个空数据源 在使用Paint事件后,我尝试再次分配数据源,但尽管我在DataGridViewComboxCell中看到值和显示正确值的标签,但我进入了一个无限循环,因此我看到GUI不断闪烁 10倍

我希望在同一datagridview列中有两个控件

我想自定义DataGridViewComboxCell,这样它将显示所选值的值,并在其上显示带有一些文本的浮动标签。在过去,我可以通过复选框和标签来实现这一点,但DataGridViewComboxCell的问题是,当我重写paint事件时,它会显示一个空数据源

在使用Paint事件后,我尝试再次分配数据源,但尽管我在DataGridViewComboxCell中看到值和显示正确值的标签,但我进入了一个无限循环,因此我看到GUI不断闪烁

10倍的帮助

代码如下:

*当窗体加载时

MyDGVCheckBoxColumn col = new MyDGVCheckBoxColumn();
        col.DataPropertyName = "value";
        col.DataSource = list;
        col.DisplayMember = "Yes";
        col.ValueMember = "value";

        col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        this.dataGridView1.Columns.Add(col);
        this.dataGridView1.RowCount = 50;
通用列表的类:

public class CheckThis
{
    public string Yes { get; set; }
    public string value { get; set; }

    public CheckThis()
    {
        Yes = "gggg";
        value = "1";
    }
}
自定义DataGridViewComboxCell的代码(我在过去的某个站点使用了类似的示例)

public class MyDGVCheckBoxColumn : DataGridViewComboBoxColumn
{
    private string label;

    public string Label
    {
        get
        {
            return label;
        }
        set
        {
            label = value;
        }
    }

    public override DataGridViewCell CellTemplate
    {
        get
        {
            return new MyDGVCheckBoxCell();
        }
    }
}

public class MyDGVCheckBoxCell : DataGridViewComboBoxCell
{
    private string label;

    public string Label
    {
        get
        {
            return label;
        }
        set
        {
            label = value;
        }

    }

    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)
    {

        // the base Paint implementation paints the check box
        base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

        // Get the check box bounds: they are the content bounds
        Rectangle contentBounds = this.GetContentBounds(rowIndex);

        // Compute the location where we want to paint the string.
        Point stringLocation = new Point();
        stringLocation.Y = cellBounds.Y + 30;

        stringLocation.X = cellBounds.X + contentBounds.Bottom;


        // Paint the string.
        var res = false;
        MyDGVCheckBoxColumn col = (MyDGVCheckBoxColumn)this.OwningColumn;
        col.DataSource = list;
        col.DisplayMember = "Yes";
        col.ValueMember = "value";


                this.label = "Customer Does Not Appear";


        graphics.DrawString(
        this.Label, new Font("Arial", 6, FontStyle.Bold), System.Drawing.Brushes.Red, stringLocation);

    }


    public object list { get; set; }
}