我使用此代码在Datagridview的Header中找到一个复选框。但是,通过更改datagridview的滚动条,找到复选框的位置。
// customize dataviewgrid, add checkbox column
DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
checkboxColumn.Width = 30;
checkboxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns.Insert(0, checkboxColumn);
// add checkbox header
Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
// set checkbox header to center of header cell. +1 pixel to position correctly.
rect.X = rect.Location.X + 8;
rect.Y = rect.Location.Y + 10;
rect.Width = rect.Size.Width;
rect.Height = rect.Size.Height;
CheckBox checkboxHeader = new CheckBox();
checkboxHeader.Name = "checkboxHeader";
checkboxHeader.Size = new Size(15, 15);
checkboxHeader.Location = rect.Location;
checkboxHeader.CheckedChanged += new EventHandler(checkboxHeader_CheckedChanged);
dataGridView1.Controls.Add(checkboxHeader);
喜欢这张照片:
答案 0 :(得分:0)
这很容易。我使用这段代码并解决了它。
dataGridView1.Columns[0].Frozen = true;