关于DataGridView设置DispalyIndex后显示顺序不正确问题
编辑器vs2005
测试程序:
winform程序界面上已经存在一个DataGridView控件dataGridView1
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = CreateTestTable();
SetColumnsOrder(dataGridView1);
}
private void SetColumnsOrder(DataGridView dgv)
{
dataGridView1.Columns[ "AccountID "].DisplayIndex = 0;
dataGridView1.Columns[ "RelationItemTypeID "].DisplayIndex = 1;
dataGridView1.Columns[ "RelationItemID "].DisplayIndex = 2;
dataGridView1.Columns[ "OperationDate "].DisplayIndex = 3;
dataGridView1.Columns[ "CreateDate "].DisplayIndex = 4;
dataGridView1.Columns[ "OperationValue "].DisplayIndex = 5;
dataGridView1.Columns[ "Remark "].DisplayIndex = 6;
dataGridView1.Columns[ "LastChangeTime "].DisplayIndex = 7;
dataGridView1.Columns[ "ID "].DisplayIndex = 8;
dataGridView1.Columns[ "BusinessTableCode "].DisplayIndex = 9;
}
//这是测试
private DataTable CreateTestTable()
{
DataTable dt = new DataTable();
DataColumn colID = new DataColumn( "ID ");
DataColumn colOperationValue = new DataColumn( "OperationValue ");
DataColumn colOperationDate = new DataColumn( "OperationDate ");