Results 1 to 2 of 2

Thread: [2.0] Refresh listview data?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    [2.0] Refresh listview data?

    I have a class that inherits a listviewitem. How do I force the listview to update the display?

    Code:
    public class AClass : System.Windows.Forms.ListViewItem
    {   
        const string booltrue = "Yes";
        const string boolfalse = "No";
    
        private ListViewSubItem m_runninglv = new ListViewSubItem();
        private bool m_running = false;
        public bool Running
        {
            get { return m_running; }
            set 
            {
                m_running = value;
                m_runninglv.Text = (m_running) ? booltrue : boolfalse;
            }
        }
    
        public AClass()
        {
            this.SubItems[0] = m_runninglv;
        }
    }
    When I change "AClass.Running" it doesn't update the text. Is there a way to force the listview to redraw the text? I tried ListView.Invalidate, etc but it didn't work.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2.0] Refresh listview data?

    This is not correct:
    Code:
    this.SubItems[0] = m_runninglv;
    It should be:
    Code:
    this.SubItems.Add(this.m_runninglv);
    The subitem at index 0 corresponds to the item itself, so myListViewItem.Text is functionally equivalent to myListViewItem.SubItems[0].Text. If you add a subitem it will be at index 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