Add a GridViewCheckBoxColumn to the GridView and set its EnableHeaderCheckBox property to true. An exception is caused when the column is hidden and the Readonly property of the GridView is set.
The test code is as follows: Press Btn1 and then Btn2 to trigger an exception.public partial class RadForm1 : RadForm
{
private bool flag1 = false;
private bool flag2 = false;
private GridViewCheckBoxColumn checkColumn;
public RadForm1()
{
InitializeComponent();
AddCheckColumn();
AddButton();
this.radGridView1.RowCount = 10;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.MasterTemplate.AllowAddNewRow = false;
}
private void AddCheckColumn()
{
checkColumn = new GridViewCheckBoxColumn();
checkColumn.Name = "Select";
checkColumn.HeaderText = "All";
checkColumn.EnableHeaderCheckBox = true;
this.radGridView1.Columns.Insert(0, checkColumn);
this.radGridView1.HeaderCellToggleStateChanged += RadGridView1_HeaderCellToggleStateChanged;
this.radGridView1.Columns.Add(new GridViewTextBoxColumn("A"));
this.radGridView1.Columns.Add(new GridViewTextBoxColumn("B"));
}
private void RadGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
{
MessageBox.Show($"State:{e.State}");
}
private void AddButton()
{
Button btn1 = new Button();
btn1.Text = "Btn1";
btn1.Click += (o, e) =>
{
checkColumn.IsVisible = flag1;
flag1 = !flag1;
};
btn1.Location = new Point(5, 5);
this.Controls.Add(btn1);
Button btn2 = new Button();
btn2.Text = "Btn2";
btn2.Click += (o, e) =>
{
if (flag2)
radGridView1.Hide();
else
{
radGridView1.Show();
try
{
radGridView1.ReadOnly = flag2;
}
catch { }
}
flag2 = !flag2;
};
btn2.Location = new Point(120, 5);
this.Controls.Add(btn2);
}
}