Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET ListView column order problem
    primarykey
    data
    text
    <p>I have a problem in a form, where I've added columns to a .NET ListView control, in the following order:</p> <pre><code>A | B | C | D </code></pre> <p>The display index for columns A-D is 0-3, in that order, yet they display in the wrong order:</p> <pre><code>A | B | D | C ^-----^ these are switched at runtime </code></pre> <p>Note: Everything looks as I want it at design time.</p> <p>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.</p> <p>Yet the problem persists.</p> <p>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.</p> <p>What else do I need to check to figure out why one of my columns is in the wrong position?</p> <p>I figured out the problem. For some reason the DisplayIndex property isn't persisted, even if I set it in the dialog.</p> <p>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.</p> <p>The code that added the columns, was like this:</p> <pre><code>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"; </code></pre> <p>When I added the missing properties directly in the file, it worked.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload