dataGridView添加、固定、调整列顺序

                //添加列,typeof为当前列的数据类型
                dt.Columns.Add("科目编码", typeof(int));
                dt.Columns.Add("科目名称", typeof(string));
                dt.Columns.Add("月份", typeof(double));
               //固定列
                dataGridView1.Columns["公司名称"].DataPropertyName = "公司名称";
                dataGridView1.Columns["年度"].DataPropertyName = "年度";
                dataGridView1.Columns["科目编码"].DataPropertyName = "科目编码";
                dataGridView1.Columns["科目名称"].DataPropertyName = "科目名称";
                dataGridView1.Columns["月份"].DataPropertyName = "月份";
                dataGridView1.Columns["本期借方数量"].DataPropertyName = "本期借方数量";
                dataGridView1.Columns["本期借方金额"].DataPropertyName = "本期借方金额";
                dataGridView1.Columns["本期贷方数量"].DataPropertyName = "本期贷方数量";
                dataGridView1.Columns["本期贷方金额"].DataPropertyName = "本期贷方金额";
                //调整列顺序,第一列为0
                dataGridView1.Columns["公司名称"].DisplayIndex = 0;
                dataGridView1.Columns["年度"].DisplayIndex = 1;
                dataGridView1.Columns["科目编码"].DisplayIndex = 2;
                dataGridView1.Columns["科目名称"].DisplayIndex = 3;
                dataGridView1.Columns["月份"].DisplayIndex = 4;
                dataGridView1.Columns["本期借方数量"].DisplayIndex = 5;
                dataGridView1.Columns["本期借方金额"].DisplayIndex = 6;
                dataGridView1.Columns["本期贷方数量"].DisplayIndex = 7;
                dataGridView1.Columns["本期贷方金额"].DisplayIndex = 8;

你可能感兴趣的:(dataGridView添加、固定、调整列顺序)