private void listLog_ColumnClick(object sender, ColumnClickEventArgs e) { ListViewItemColumnSorter columnSorter = new ListViewItemColumnSorter(); listLog.ListViewItemSorter = columnSorter; columnSorter.curColumn = e.Column; listLog.Sort(); listLog.ListViewItemSorter = null; }
private void UpdateListLogList(List<string[]> msgs) { listLog.SuspendLayout(); listLog.Items.Clear(); foreach (string[] msg in msgs) { ListViewItem listViewItem1 = new ListViewItem(msg); listViewItem1.ImageIndex = (msg[0] == "error") ? 1 : 0; // Subtract 1 because we want 1 based (not 0 based) string lineNo = listViewItem1.SubItems[1].Text; int lineNoInt; if (Int32.TryParse(lineNo, out lineNoInt)) if (lineNoInt > 0) listViewItem1.SubItems[1].Text = (lineNoInt - 1).ToString(); listLog.Items.Add(listViewItem1); } // Now sort the columns ListViewItemColumnSorter columnSorter = new ListViewItemColumnSorter(); listLog.ListViewItemSorter = columnSorter; columnSorter.int_mode = true; columnSorter.curColumn = listLog.Columns[1].Index; // first sort by line # listLog.Sort(); columnSorter.int_mode = false; columnSorter.curColumn = listLog.Columns[0].Index; // then sort by type listLog.Sort(); listLog.ListViewItemSorter = null; listLog.ResumeLayout(); }