本文介绍了datagridview列显示索引无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



i对datagridview有一点问题,我需要重新排序datagridview中的列







我在datagridview中加载了10列,其中5列是不可见的,我用简单的代码看不见







其余5我想按照displayindex属性订购



和这里是现在的事情



我输入代码



dg.AutoGenerateColumns = false;



dg.Columns [Column1] .Visible = false;

dg.Columns [Column2] .Visible = false;

dg.Columns [Column3] .Visible = false;

dg.Columns [Column4] .Visible = false;

dg.Columns [Column5]。 Visible = false;



dg.Column [Column6] .DisplayIndex = 1;

dg.Column [Column7] .DisplayIndex = 2;

dg.Column [Column8] .DisplayIndex = 3;

dg.Column [Column9] .DisplayIndex = 4;

dg.Column [Column10] .DisplayIndex = 5;



但是Column9到位3而不是4,而Column8到位8,他们改变了地方!

我甚至将其设置为将DisplayIndex-es保存到我的解决方案的Properties.Settings中,然后我将displayindexes读入每个列的文本框中以查看,并且其中有人认为Column9已经到位4但是IT不是,它是3月!!!!



我很困惑

帮助,任何人

Hello

i have a little issue with datagridview, I need to reorder columns in datagridview



I have 10 columns loaded into datagridview, 5 of them are invisible, which I made invisible in simple code



and the rest 5 I want to place in order with displayindex property

and here is the thing now

I put in code

dg.AutoGenerateColumns = false;

dg.Columns["Column1].Visible = false;
dg.Columns["Column2].Visible = false;
dg.Columns["Column3].Visible = false;
dg.Columns["Column4].Visible = false;
dg.Columns["Column5].Visible = false;

dg.Column["Column6].DisplayIndex = 1;
dg.Column["Column7].DisplayIndex = 2;
dg.Column["Column8].DisplayIndex = 3;
dg.Column["Column9].DisplayIndex = 4;
dg.Column["Column10].DisplayIndex = 5;

but Column9 gets on place 3 not 4, while Column8 gets on place 8, THEY CHANGE PLACES!!!
I even set it up to save DisplayIndex-es into Properties.Settings of my solution and then I read the displayindexes into textboxes for each column to see, and THERE IT SAYS Column9 is on place 4 but IT IS NOT, it's on 3!!!!

I am puzzled
help, anyone

推荐答案

dg.Columns["Column1"].Visible = false;
dg.Columns["Column2"].Visible = false;
dg.Columns["Column3"].Visible = false;
dg.Columns["Column4"].Visible = false;
dg.Columns["Column5"].Visible = false;

dg.Column["Column6"].DisplayIndex = 1;
dg.Column["Column7"].DisplayIndex = 2;
dg.Column["Column8"].DisplayIndex = 3;
dg.Column["Column9"].DisplayIndex = 4;
dg.Column["Column10"].DisplayIndex = 5;

dg.Column["Column1"].DisplayIndex = 6;
dg.Column["Column2"].DisplayIndex = 7;
dg.Column["Column3"].DisplayIndex = 8;
dg.Column["Column4"].DisplayIndex = 9;
dg.Column["Column5"].DisplayIndex = 10;



dg.Columns["Column1"].Visible = false;
dg.Columns["Column2"].Visible = false;
dg.Columns["Column3"].Visible = false;
dg.Columns["Column4"].Visible = false;
dg.Columns["Column5"].Visible = false;

dg.Column["Column6"].DisplayIndex = 1;
dg.Column["Column7"].DisplayIndex = 2;
dg.Column["Column8"].DisplayIndex = 3;
dg.Column["Column9"].DisplayIndex = 4;
dg.Column["Column10"].DisplayIndex = 5;

dg.Column["Column1"].DisplayIndex = 6;
dg.Column["Column2"].DisplayIndex = 7;
dg.Column["Column3"].DisplayIndex = 8;
dg.Column["Column4"].DisplayIndex = 9;
dg.Column["Column5"].DisplayIndex = 10;





}



}


这篇关于datagridview列显示索引无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:28