public ColumnHeaderEx(string text) { this.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); ColumnState state = new ColumnState("string", false); this.Tag = state; this.ImageIndex = -1; this.Text = text; }
public ColumnHeaderEx(string text) { this.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); ColumnState state = new ColumnState("string", false); this.Tag = state; this.ImageIndex = -1; this.Text = text; }
protected override void OnColumnClick(ColumnClickEventArgs e) { base.OnColumnClick(e); //set the images on the column headers to none if (this.SmallImageList != null) { foreach (ColumnHeader ch in this.Columns) { ch.ImageIndex = -1; } } //prepare for sorting the columns ListViewItemComparer comparer = new ListViewItemComparer(e.Column); ColumnState state = this.Columns[e.Column].Tag as ColumnState; if (state != null) { if (state.type == "number") { comparer.Numeric = true; } else if (state.type == "date") { comparer.Date = true; } state.descending = !state.descending; //toggle state from acsending to desending and vice versa on very click ColumnHeader column = this.Columns[e.Column]; if (this.SmallImageList != null) { if (state.descending) { column.ImageIndex = 0; } else { column.ImageIndex = 1; } } comparer.Descending = state.descending; } this.ListViewItemSorter = comparer; this.Sort(); //set the colors. this.BeginUpdate(); Color c = Color.FromArgb(247, 247, 247); //change the column color int idx = 0; foreach (ListViewItem lvi in this.Items) { if (previousColumn != -1) { lvi.SubItems[previousColumn].ResetStyle(); } //paint alternate rows if ((idx & 1) == 0) //if even { lvi.BackColor = c; //Paint subitems foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems) { lvsi.BackColor = c; } } else //if odd { lvi.BackColor = this.BackColor; foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems) { lvsi.BackColor = this.BackColor; } } lvi.SubItems[e.Column].BackColor = c; idx++; } previousColumn = e.Column; this.EndUpdate(); }