gpt4 book ai didi

c# - Datagridview 中的锚定复选框

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:14 25 4
gpt4 key购买 nike

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

我在其中一个标题栏中使用了 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);
//

最佳答案

您可以使用 datagridview 的“滚动”事件来执行如下操作:

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;
}
}

迟到总比不到好?

关于c# - Datagridview 中的锚定复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13565075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com