May I ask why exactly you need to select an item in the listView from the code?  Would you have an item that you would want to default.  You were expecting America, so I guess you could loop through your listView and check that ListView1.Items[index].Text = "America" (syntax may not be exactly correct) and then set that item to selected.  I guess I am not sure why you would want to select an item from your code unless it was a default value or you could just want to select the first value. 

On 7/28/05, Babu Aboobacker <[EMAIL PROTECTED]> wrote:
Hi Chris ,
 
Thanks for your reply.
 
At very first, i too worried that this malfunctioning is due to some reference keeping issue and so I tried to clera whole the reference forcefully ( GC.Collect() and WaitForPendingFinalizers) . But no luck !
 
The source code in my first mail was just a sample code.
 
I can't hard code the items in real case.
 
One thing i can do here is to take out the sorting functionality outside the listview and then create  the list view with the sorted items. But if we have multiple columns and like to give sorting functionality based on each column ( in a windows explorer like application) it is not feasible solution. True ?
 
Regards,
Aboobacker
 
----- Original Message -----
Sent: Thursday, July 28, 2005 9:15 PM
Subject: Re: [Microsofts_C_Sharp] C# List View Sorting Issue

 
Must be because it still keeps a reference to where it was.  And your problem is?  Are you just trying to set a default.  You're hard coding the names in.  Just hard code them in alphabetical order or sort the names first, then add to your ListView control.

On 7/28/05, BABU ABOOBACKER <[EMAIL PROTECTED] > wrote:
Dear Friends,
 
I have expereinced a weird problem related to C# ListView control sorting.
 
In my Form's constructor i have added some list view items , then sort it ascendig oredr an dthen i tried to select the first item in the listview and expect that it will select the first item in the sorted list.
 
But surprisingly it selects the first item added to the list view !
 
But when i move the item selection cod eto Form.Load event handler or Form.Activated event handler it is working as expected !
 
Is this any bug or already documented somewhere in MSDN?  
 
Here is the code snippet.
 
  public Form1()
  {
           
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();
 
   ......................
   ......................
 
            listView1.ListViewItemSorter = new ListViewItemComparer(0,SortOrder.Ascending);
 
            this.listView1.Items.Add("India");
            this.listView1.Items.Add("France");
            this.listView1.Items.Add("America");
            this.listView1.Items.Add("Russia");
            this.listView1.Items.Add("Japan");
 
            listView1.Sort();
 
            //This doesn't select the item "America" but selects the item "India"
          // If we move this to Form.Load or Form.Activated event handler it selects teh item "America".
            listView1.Items[0].Selected = true;
}
 
Any idea ?
 
 
Regards,
Aboobacker


YAHOO! GROUPS LINKS






YAHOO! GROUPS LINKS






YAHOO! GROUPS LINKS




Reply via email to