求助:winform中dataGridView的列头问题
private void btn_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = 数据集合;
}
当我每次点击按钮后,dataGridView的列的顺序都会改变
如:
记录号 姓名 年龄 性别
1 aa 20 男
2 bb 30 女
点击按钮后变成:
记录号 年龄 姓名 性别
1 20 aa 男
2 30 bb 女
每次改变的顺序都没有规律,请问如何能控制住列的顺序,不让他变呢?谢谢了
------解决方案--------------------#region 固定列的顺序
private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
GV_ZZWGL.Columns[ "Column1 "].DisplayIndex = 0;
GV_ZZWGL.Columns[ "GV_GSDS "].DisplayIndex = 1;
GV_ZZWGL.Columns[ "Column3 "].DisplayIndex = 2;
GV_ZZWGL.Columns[ "Column4 "].DisplayIndex = 3;
GV_ZZWGL.Columns[ "Column6 "].DisplayIndex = 4;
GV_ZZWGL.Columns[ "Column7 "].DisplayIndex = 5;
GV_ZZWGL.Columns[ "Column8 "].DisplayIndex = 6;
GV_ZZWGL.Columns[ "Column5 "].DisplayIndex = 7;
GV_ZZWGL.Columns[ "xjje "].DisplayIndex = 8;
GV_ZZWGL.Columns[ "GV_ZPJE "].DisplayIndex = 9;
GV_ZZWGL.Columns[ "Column11 "].DisplayIndex = 10;
}
#endregion