我想在表单加载时按列对 DataGridView 进行排序,但出现异常。
private void frm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dataSetExclusion.Exclude' table. You can move, or remove it, as needed.
this.excludeTableAdapter.Fill(this.dataSetExclusion.Exclude);
this.dgv.Sort(this.dgv.Columns["ID"], ListSortDirection.Ascending);
}
DataGridView dgv 中的列标题为“ID”。它的 DataPropertyName 是“ExcludeID”。我为列名尝试了“ID”和“ExcludeID”,但仍然出现异常。
Value cannot be null.Parameter name: dataGridViewColumn