.NET ListView中列的顺序问题顺序、问题、NET、ListView

2023-09-04 08:40:51 作者:王牌;

我有一个形式,在那里我已经添加列到.NET ListView控件的一个问题,按以下顺序:

I have a problem in a form, where I've added columns to a .NET ListView control, in the following order:

A   | B   | C   | D

有关列AD显示指数为0-3,按照这个顺序,但他们以错误的顺序显示:

The display index for columns A-D is 0-3, in that order, yet they display in the wrong order:

A   | B   | D   | C
            ^-----^  these are switched at runtime

请注意:一切看起来都像我希望它在设计时

Note: Everything looks as I want it at design time.

我想,但我不知道为什么,那是因为我加了C列到ListView后,我又增加了列D.我把它列编辑器对话框一个档次,调整了显示指标,并检查创建顺序在了.Designer.cs文件,一切都是为了AD,按照这个顺序。

I guess, but I don't know why, that it is because I added column C to the ListView after I had added column D. I moved it up a notch in the column editor dialog, adjusted the display indices, and checked the creation order in the .Designer.cs file, everything is in order A-D, in that order.

然而,问题仍然存在。

另外请注意:这不只是一个标题标签的问题,列换各地,包括他们的数据。该数据在我期待它的显示顺序添加,但最后两列互换。

Also note: This is not just a heading label issue, the columns are swapped around, including their data. The data is added in the order I expect it to be displayed, but the last two columns are swapped.

还有什么,我需要检查,找出原因,我的专栏之一,是在错误的位置?

What else do I need to check to figure out why one of my columns is in the wrong position?

我想通了这个问题。出于某种原因,的DisplayIndex财产不保留,即使我在对话框中设置。

I figured out the problem. For some reason the DisplayIndex property isn't persisted, even if I set it in the dialog.

如果我已经完全封闭的形式,并在Visual Studio中重新打开它,然后它被到处转移。显然不是由对话框编辑器检测到的这些属性为改变,从而节约的机制不小心将它保存为我满意。

If I had completely closed the form, and reopened it in Visual Studio, then it shifted around. Apparently those properties aren't detected by the dialog editor as "changed", and thus the save mechanism doesn't care to save it for me either.

这是添加的栏目,code是这样的:

The code that added the columns, was like this:

this.lvResult = new System.Windows.Forms.ListView();
this.colResultId = new System.Windows.Forms.ColumnHeader();
this.colResultTitle = new System.Windows.Forms.ColumnHeader();
this.colResultLanguage = new System.Windows.Forms.ColumnHeader();
this.colResultTags = new System.Windows.Forms.ColumnHeader();
// 
// lvResult
// 
this.lvResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
this.lvResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colResultId,
this.colResultTitle,
this.colResultLanguage,
this.colResultTags});
this.lvResult.FullRowSelect = true;
this.lvResult.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lvResult.HideSelection = false;
this.lvResult.Location = new System.Drawing.Point(12, 6);
this.lvResult.Name = "lvResult";
this.lvResult.Size = new System.Drawing.Size(466, 117);
this.lvResult.TabIndex = 0;
this.lvResult.UseCompatibleStateImageBehavior = false;
this.lvResult.View = System.Windows.Forms.View.Details;
this.lvResult.SelectedIndexChanged += new System.EventHandler(this.lvResult_SelectedIndexChanged);
// 
// colResultId
// 
this.colResultId.Text = "#";
this.colResultId.Width = 35;
// 
// colResultTitle
// 
this.colResultTitle.Text = "Title";
this.colResultTitle.Width = 220;
// 
// colResultTags
// 
this.colResultTags.DisplayIndex = 2;
this.colResultTags.Text = "Tags";
this.colResultTags.Width = 100;
// 
// colResultLanguage
// 
this.colResultLanguage.Text = "Language";

当我直接在文件中添加缺少的属性,它的工作。

When I added the missing properties directly in the file, it worked.

推荐答案

时,它也许坚持的东西窗体的.resx而不是.designer?我无法想象的为什么的它会做到这一点,但是,是...

Is it perhaps persisting something to the form's .resx instead of the .designer? I can't imagine why it'd do that, but yeah...

也许,如果这些方法都失败,请尝试从表单删除ListView控件。然后,在项目中创建一个新的垃圾形式重现的ListView垃圾形式,测试垃圾的形式,以确保你没有得到的怪异巫术行为,然后再从垃圾形式复制回ListView控件到你的真正形成?

Maybe if all else fails, try deleting the ListView from your form. Then, create a new junk form in your project recreating the ListView on the junk form, test the junk form to make sure you're not getting the weird voodoo behavior, and then copy the ListView from the junk form back to your real form?

费解得要命,我知道......

Terribly convoluted, I know...

 
精彩推荐
图片推荐