I have a button \"Show data\". When click it, data will display in list view. But I want to clear it and then click \"Show data\" again to display new data. Because I don\'t
listView1.Items.Clear();
Clears in 2008 c# column headers with the data, if you have multiple ListView on the same form the best way is writing a method such as (suggested by Lasse as above)
private void ClearLvItems(ListView li)
{
while(li.Items.Count>1)
li.Items.RemoveAt(1);
}
Or if it does not work as expected as it does not work with me (one row still rests in Listview)
listView1.Items.Clear();
SetHeaders(li); // If you have more then one ListView in the same form. Otherwise don't use the parameters.
private void SetHeader(ListView li)
{
string[] header_names = new string[] {"Id","Name","SurName","Birth Date"};
int i = 0;
foreach (ColumnHeader ch in li.Columns)
{
ch.Text = header_names[i];
++i;
}
}
Another discussion is Here