/// <summary> /// Bind listview of main window /// </summary> private void listView_ShowBD_DataBinding() { try { ListArticle = ArticleController.GetAllArticle(); listView_ShowBD.Items.Clear(); this.BindDataToView(this.MakeListItem()); } catch (Exception E) { MessageBox.Show("No database file found! Please put database file in right place.\n" + E.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Information); System.Environment.Exit(0); } }
private void ColumnClickFunction(object sender, ColumnClickEventArgs e) { ArticleController ArticleController = new ArticleController(); ListArticle = ArticleController.GetAllArticle(); int Column = e.Column; if (Column == 2 || Column == 3) { this.listView_ShowBD.Groups.Clear(); this.listView_ShowBD.Items.Clear(); // sub familly List <string> GroupString = new List <string>(); List <ListViewGroup> GroupList = new List <ListViewGroup>(); ListViewItem[] L_Item = this.MakeListItem(); foreach (ListViewItem Item in L_Item) { // create group list if (!GroupString.Contains(Item.SubItems[Column].Text)) { ListViewGroup Group = new ListViewGroup(Item.SubItems[Column].Text, HorizontalAlignment.Left); GroupList.Add(Group); Item.Group = Group; GroupString.Add(Item.SubItems[Column].Text); } else { int Index = GroupString.IndexOf(Item.SubItems[Column].Text); Item.Group = GroupList.ElementAt(Index); } } foreach (ListViewGroup Group in GroupList) { this.listView_ShowBD.Groups.Add(Group); } this.BindDataToView(L_Item); } else if (Column == 0 || Column == 1) { this.listView_ShowBD.Groups.Clear(); } // Determine whether the column is the same as the last column clicked. /* if (e.Column != sortColumn) * { * // Set the sort column to the new column. * sortColumn = e.Column; * // Set the sort order to ascending by default. * listView_ShowBD.Sorting = System.Windows.Forms.SortOrder.Ascending; * } * else * { * // Determine what the last sort order was and change it. * if (listView_ShowBD.Sorting == System.Windows.Forms.SortOrder.Ascending) * listView_ShowBD.Sorting = System.Windows.Forms.SortOrder.Descending; * else * listView_ShowBD.Sorting = System.Windows.Forms.SortOrder.Ascending; * } */ listView_ShowBD.Sorting = System.Windows.Forms.SortOrder.Ascending; // Call the sort method to manually sort. listView_ShowBD.Sort(); // Set the ListViewItemSorter property to a new ListViewItemComparer // object. this.listView_ShowBD.ListViewItemSorter = new ListViewItemComparer(e.Column, listView_ShowBD.Sorting); }