Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET: ListView blues?
    primarykey
    data
    text
    <p>Selection count, <code>.SelectedItems.Count</code>, does not change when the <code>Selected</code> property is set to true on an item in the <code>Items</code> collection of a <code>ListView</code>.</p> <p>Example:</p> <pre><code> lvPept.SelectedItems.Clear() lvPept.Items(6).Selected = True Dim newLen As Integer = lvPept.SelectedItems.Count </code></pre> <p><code>lvPept</code> is a <code>ListView</code> and contains 10 elements.</p> <p><code>newLen</code> is expected to be 1, but is 0 when the problem occurs and the <code>SelectedIndexChanged</code> event is <strong><em>not</em></strong> fired. With other datasets it is 1 as expected and the SelectedIndexChanged event is fired.</p> <p>Under what circumstance or in what state can <code>lvPept</code> be in for this to happen? <code>BeginUpdate</code>()/<code>EndUpdate</code>() is <strong><em>not</em></strong> used with <code>lvPept</code>.</p> <p>Background:</p> <p>I am trying to track down a problem one of the users of my open source .NET application, MSQuant (<a href="http://msquant.sourceforge.net/" rel="nofollow noreferrer">http://msquant.sourceforge.net/</a>), encountered.</p> <p>I have run out of ideas of what could be the cause of this problem.</p> <p>The problem is reproducible, and I can reproduce it in my development environment, Visual Studio 2008. It seems to be independent of the Windows version (Windows 2000/Windows XP 32 bit/ Windows XP 64 bit), the .NET runtime version (2.0/3.5) and Visual Studio version (2005/2008).</p> <p>Other context: the application is written in VB.NET and in C# and is a Windows Forms application. The source code for the class in question is at <a href="http://shrinkster.com/14bg" rel="nofollow noreferrer">http://shrinkster.com/14bg</a>. The form class that the <code>ListView</code> is in was initially generated by one of earliest official versions of Visual Studio that supported .NET, ca. 2002.</p> <p>Update 1: as I have both a working case and a broken case I have compared the content of <code>lvPept</code>. The only difference except for properties "Handle", "MousePosition" and "TopItem" (as it is a different protein with different peptides) is property "Created". It was False for the broken case. It makes sense that a partly constructed object can not function properly, but how can it happen?</p> <p>Update 2: property "Created" being false turned out to be a good lead. I think the real problem was doing this at <strong>construction</strong> time and not at <strong>form load</strong> time. I have now added ASSERTs for property "Created", refactored and changed all the operations to happen at form load time. It now works as expected and the user with the problem has got a new version of the application.</p> <p>The old bad way had been in there since the application's inception in 2002. I am just wondering if some experts could throw light on why it worked 99.9% of the time and only failed in a few cases and reproducably so.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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