我在 Windows 窗体应用程序中编写了一个代码来更改标题名称。
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.Beige;
columnHeaderStyle.Font = new Font("Bookman Old Style", 8, FontStyle.Bold);
dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
dataGridView1.Columns[0].HeaderText = "Item Code";
dataGridView1.Columns[1].HeaderText = "Item Name";
但是当我运行这段代码时,会出现错误。” Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
“我该如何解决?