CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Saint Paul, Minnesota, US
    Posts
    91

    Selecting specific row using ListView

    Hi ...

    I am using C# and System.Windows.Forms.ListView. I do not see the method that will allow me to select a specific row by index.

    My objective is to always keep the last row in the ListView selected and visable.

    Using Visual C++ and a ListBox I would do somethings like:
    m_ctrlResults.AddString(csMessage);
    nCount = m_ctrlResults.GetCount();
    m_ctrlResults.SetCurSel(nCount - 1);

    Here is my code,
    Thanks,
    Chris


    Code:
            public void WriteStatusMessage(int nSeverity, string strMessage)
            {
                string strDate; 
                string strSeverity; 
                int     nIndex = 0; 
                
                // Add some rows
                ListViewItem item = new ListViewItem();
                
    
                item.Text = strSeverity;
                item.SubItems.Add(strDate);
                item.SubItems.Add(strMessage);
                listView1.Items.Add(item);
                listView1.ResumeLayout();
    			
                // listView1.EnsureVisible(0); 
    
            }

  2. #2
    Join Date
    May 1999
    Location
    Saint Paul, Minnesota, US
    Posts
    91

    Re: Selecting specific row using ListView

    Hi ...

    Use the ListView.ListViewItemCollection property ... which will contain the count of the items in the ListView. Then use the EnsureVisible() method.

    The code is below:
    010010111001
    Chris
    Code:
    			
    ListView.ListViewItemCollection lvic = new ListView.ListViewItemCollection(listView1); 
    nIndex = lvic.Count; 
    listView1.EnsureVisible(nIndex - 1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured