在Datagridview中锚定复选框

时间:2012-11-26 12:42:29

标签: c# winforms datagridview

我正在创建一个基于winform的桌面应用程序,我正在使用Datagridview来填充数据。

我在其中一个标题栏中使用checkbox。桌子很安静,适合屏幕,我使用滚动条在水平和垂直方向移动。

checkbox需要在滚动条移动时移动。但问题是它仍然是静态的。

任何想法如何锚定它,以便当滚动条移动时,复选框会相应移动。enter image description here

由于

编辑:

自动生成设计师代码:

            this.checkheader.AutoSize = true;
            this.checkheader.BackColor = System.Drawing.Color.White;
            this.checkheader.FlatAppearance.BorderColor = System.Drawing.Color.White;
            this.checkheader.Location = new System.Drawing.Point(49, 96);
            this.checkheader.Name = "checkheader";
            this.checkheader.Size = new System.Drawing.Size(15, 14);
            this.checkheader.TabIndex = 21;
            this.checkheader.UseVisualStyleBackColor = false;
            this.checkheader.CheckedChanged += new System.EventHandler(this.checkboxHeader_CheckedChanged);
        // 

1 个答案:

答案 0 :(得分:0)

您可以使用datagridview'roll'事件来执行以下操作:

private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
    {
        if (e.ScrollOrientation.Equals(ScrollOrientation.HorizontalScroll))
        {
            checkBox1.Location = new Point(checkBox1.Location.X - (e.NewValue - e.OldValue), checkBox1.Location.Y);
        }
        if (checkBox1.Location.X < dataGridView1.Location.X + 40)
        {
            checkBox1.Visible = false;
        }
        else
        {
            checkBox1.Visible = true;
        }
    }

迟到总比没有好?