[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.
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.