I was looking for a solution for this, but I failed. I could not find anyone that would best answer this problem, so I made my decision. I am very glad that I was able to make this solution shorter, easier and more understandable, but the best answer is what most of us are looking for.
public void ShowCurrentParked() { dt3 = new DataTable(); dt3.Clear(); //clear to avoid overlapping data (new DataTable is not enough) lstViewShowCurrentParked.Items.Clear(); //clear items to accept new or updated data to avoid overlapping/duplicate data dt3 = pBAL.ShowCurrentParked(); //datasource (class) for (int j = 0; j < dt3.Rows.Count; j++) { lstViewShowCurrentParked.BeginUpdate(); lstViewShowCurrentParked.Items.Add(new ListViewItem(new string[] {dt3.Rows[j][1].ToString(),dt3.Rows[j][2].ToString(), dt3.Rows[j][3].ToString()})); } lstViewShowCurrentParked.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); lstViewShowCurrentParked.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); lstViewShowCurrentParked.EndUpdate(); dt3.Clear(); //clear again to avoid overlapping data (new DataTable is not enough) .. to make datatable really empty //BeginUpdate and EndUpdate will just lessen the flicker during listview update }
Efficiency: 1. Fast 2. Avoid data duplication 3. Less flicker
user5146033
source share