我有这样的数据网格视图
当我尝试单击列标题以尝试对数据进行排序时,程序会在线中断
DataGridViewRow row = dataGridView1.Rows[rowIndex];
ArgumentOutOfRangeException 未处理。指数超出范围。必须是非负数且小于集合的大小。参数名称:索引
这是 .designer.cs 中的代码
this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
this.dataGridView1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.dataGridView1.BackgroundColor = System.Drawing.Color.Azure;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(21, 62);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(586, 381);
this.dataGridView1.TabIndex = 9;
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick_1);
这是我的 .cs 中的代码
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
DataGridViewRow row = dataGridView1.Rows[rowIndex];
groupBoxPenghuni.Visible = false;
groupBoxStaff.Visible = false;
groupBoxRoom.Visible = false;
groupBoxDPenghuni.Visible = true;
groupBoxPenghasilan.Visible = false;
GroupBox_AddResident_Resident.Visible = false;
GroupBox_AddResident_Room.Visible = false;
GroupBox_AddResident1.Visible = false;
GroupBox_DeleteResident_Resident.Visible = false;
GroupBox_DeleteResident1.Visible = false;
GroupBox_Resident.Visible = false;
GroupBox_Update_Room.Visible = false;
GroupBox_UpdateResident1.Visible = false;
}
有什么问题?我该怎么办?