From: <ze...@us...> - 2007-04-04 20:17:56
|
Revision: 288 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=288&view=rev Author: zebons Date: 2007-04-04 13:17:41 -0700 (Wed, 04 Apr 2007) Log Message: ----------- Add sort function by Header Column clic Modified Paths: -------------- trunk/plugins/mpinstaler/MPInstaler/Form1.Designer.cs trunk/plugins/mpinstaler/MPInstaler/Form1.cs trunk/plugins/mpinstaler/MPInstaler/Language dialog.Designer.cs trunk/plugins/mpinstaler/MPInstaler/Language dialog.cs Modified: trunk/plugins/mpinstaler/MPInstaler/Form1.Designer.cs =================================================================== --- trunk/plugins/mpinstaler/MPInstaler/Form1.Designer.cs 2007-04-04 18:01:46 UTC (rev 287) +++ trunk/plugins/mpinstaler/MPInstaler/Form1.Designer.cs 2007-04-04 20:17:41 UTC (rev 288) @@ -352,10 +352,12 @@ this.bossview.Location = new System.Drawing.Point(12, 52); this.bossview.Name = "bossview"; this.bossview.Size = new System.Drawing.Size(651, 215); + this.bossview.Sorting = System.Windows.Forms.SortOrder.Ascending; this.bossview.TabIndex = 2; this.bossview.UseCompatibleStateImageBehavior = false; this.bossview.View = System.Windows.Forms.View.Details; this.bossview.SelectedIndexChanged += new System.EventHandler(this.bossview_SelectedIndexChanged); + this.bossview.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.bossview_ColumnClick); // // columnHeader1 // Modified: trunk/plugins/mpinstaler/MPInstaler/Form1.cs =================================================================== --- trunk/plugins/mpinstaler/MPInstaler/Form1.cs 2007-04-04 18:01:46 UTC (rev 287) +++ trunk/plugins/mpinstaler/MPInstaler/Form1.cs 2007-04-04 20:17:41 UTC (rev 288) @@ -17,6 +17,8 @@ private MPinstalerStruct _struct = new MPinstalerStruct(); private string proiect_file_name = "Untitled"; private bool _loading = false; + public int sortColumn; + public Form1() { InitializeComponent(); @@ -419,7 +421,32 @@ } } + private void bossview_ColumnClick(object sender, ColumnClickEventArgs e) + { + // 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. + bossview.Sorting = SortOrder.Ascending; + } + else + { + // Determine what the last sort order was and change it. + if (bossview.Sorting == SortOrder.Ascending) + bossview.Sorting = SortOrder.Descending; + else + bossview.Sorting = SortOrder.Ascending; + } + // Call the sort method to manually sort. + bossview.Sort(); + // Set the ListViewItemSorter property to a new ListViewItemComparer + // object. + this.bossview.ListViewItemSorter = new ListViewItemComparer(e.Column, bossview.Sorting, true); + } + private void textToolStripMenuItem1_Click(object sender, EventArgs e) { addother(MPinstalerStruct.THUMBS_TYPE,thumbst_comboBox1.Text); Modified: trunk/plugins/mpinstaler/MPInstaler/Language dialog.Designer.cs =================================================================== --- trunk/plugins/mpinstaler/MPInstaler/Language dialog.Designer.cs 2007-04-04 18:01:46 UTC (rev 287) +++ trunk/plugins/mpinstaler/MPInstaler/Language dialog.Designer.cs 2007-04-04 20:17:41 UTC (rev 288) @@ -78,13 +78,14 @@ // this.languageComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.languageComboBox.FormattingEnabled = true; - this.languageComboBox.Location = new System.Drawing.Point(216, 252); + this.languageComboBox.Location = new System.Drawing.Point(83, 253); this.languageComboBox.Name = "languageComboBox"; - this.languageComboBox.Size = new System.Drawing.Size(168, 21); + this.languageComboBox.Size = new System.Drawing.Size(154, 21); this.languageComboBox.TabIndex = 2; // // listView1 // + this.listView1.AllowColumnReorder = true; this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); @@ -94,15 +95,18 @@ this.columnHeader3}); this.listView1.FullRowSelect = true; this.listView1.GridLines = true; - this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; - this.listView1.Location = new System.Drawing.Point(12, 12); + this.listView1.LabelEdit = true; + this.listView1.Location = new System.Drawing.Point(12, 11); this.listView1.Name = "listView1"; + this.listView1.ShowItemToolTips = true; this.listView1.Size = new System.Drawing.Size(372, 235); + this.listView1.Sorting = System.Windows.Forms.SortOrder.Ascending; this.listView1.TabIndex = 3; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick); this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick); + this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick); // // columnHeader1 // @@ -111,11 +115,13 @@ // // columnHeader2 // + this.columnHeader2.DisplayIndex = 2; this.columnHeader2.Text = "Value"; this.columnHeader2.Width = 137; // // columnHeader3 // + this.columnHeader3.DisplayIndex = 1; this.columnHeader3.Text = "Language"; this.columnHeader3.Width = 155; // @@ -130,7 +136,7 @@ // textBox2 // this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.textBox2.Location = new System.Drawing.Point(80, 253); + this.textBox2.Location = new System.Drawing.Point(243, 253); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(130, 20); this.textBox2.TabIndex = 5; @@ -149,6 +155,7 @@ // // listView2 // + this.listView2.AllowColumnReorder = true; this.listView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { @@ -163,6 +170,7 @@ this.listView2.UseCompatibleStateImageBehavior = false; this.listView2.View = System.Windows.Forms.View.Details; this.listView2.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView2_MouseDoubleClick); + this.listView2.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView2_ColumnClick); // // columnHeader4 // Modified: trunk/plugins/mpinstaler/MPInstaler/Language dialog.cs =================================================================== --- trunk/plugins/mpinstaler/MPInstaler/Language dialog.cs 2007-04-04 18:01:46 UTC (rev 287) +++ trunk/plugins/mpinstaler/MPInstaler/Language dialog.cs 2007-04-04 20:17:41 UTC (rev 288) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -16,6 +17,7 @@ public partial class Form2 : Form { public string baseDir; + public int sortColumn; public List<LanguageString> Language; public MPLanguageHelper deflang = new MPLanguageHelper(); public MPLanguageHelper lang = new MPLanguageHelper(); @@ -105,7 +107,7 @@ return; } update_listview1(textBox1.Text, textBox2.Text, languageComboBox.Text); - } + } private void button2_Click(object sender, EventArgs e) { @@ -146,7 +148,7 @@ private void button3_Click(object sender, EventArgs e) { Language.Clear(); - for(int i=0;i<listView1.Items.Count;i++) + for (int i = 0; i < listView1.Items.Count; i++) { Language.Add(new LanguageString(listView1.Items[i].SubItems[2].Text, listView1.Items[i].Text, listView1.Items[i].SubItems[1].Text)); } @@ -212,7 +214,7 @@ result = MessageBox.Show(message, caption, buttons); - if(result == DialogResult.No) + if (result == DialogResult.No) return; MPLanguageHelper mplh = new MPLanguageHelper(); foreach (string lg in languageComboBox.Items) @@ -242,7 +244,7 @@ textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text; textBox2.Text = listView1.SelectedItems[0].SubItems[1].Text; languageComboBox.Text = listView1.SelectedItems[0].SubItems[2].Text; -// listView1.Items.Remove(listView1.SelectedItems[0]); + // listView1.Items.Remove(listView1.SelectedItems[0]); } } private void listView1_MouseClick(object sender, MouseEventArgs e) @@ -269,18 +271,120 @@ break; } } - // if (!modify) - // { - ListViewItem item1 = new ListViewItem(wid, 0); - item1.SubItems.Add(wval); - item1.SubItems.Add(wlang); - listView1.Items.AddRange(new ListViewItem[] { item1 }); - // } + // if (!modify) + // { + ListViewItem item1 = new ListViewItem(wid, 0); + item1.SubItems.Add(wval); + item1.SubItems.Add(wlang); + listView1.Items.AddRange(new ListViewItem[] { item1 }); + listView1.Sort(); + // } } - private void listView2_MouseDoubleClick(object sender, MouseEventArgs e) { add_reference_value(); } - } -} \ No newline at end of file + + private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) + { + // 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. + listView1.Sorting = SortOrder.Ascending; + } + else + { + // Determine what the last sort order was and change it. + if (listView1.Sorting == SortOrder.Ascending) + listView1.Sorting = SortOrder.Descending; + else + listView1.Sorting = SortOrder.Ascending; + } + + // Call the sort method to manually sort. + listView1.Sort(); + // Set the ListViewItemSorter property to a new ListViewItemComparer + // object. + this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column, listView1.Sorting, true); + } + + private void listView2_ColumnClick(object sender, ColumnClickEventArgs e) + { + // 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. + listView2.Sorting = SortOrder.Ascending; + } + else + { + // Determine what the last sort order was and change it. + if (listView2.Sorting == SortOrder.Ascending) + listView2.Sorting = SortOrder.Descending; + else + listView2.Sorting = SortOrder.Ascending; + } + + // Call the sort method to manually sort. + listView2.Sort(); + // Set the ListViewItemSorter property to a new ListViewItemComparer + // object. + if (e.Column == 0) + this.listView2.ListViewItemSorter = new ListViewItemComparer(e.Column, listView2.Sorting, false); + else + this.listView2.ListViewItemSorter = new ListViewItemComparer(e.Column, listView2.Sorting, true); + } + } + + // Implements the manual sorting of items by columns. + class ListViewItemComparer : IComparer + { + private int col; + private SortOrder order; + public ListViewItemComparer() + { + col = 0; + order = SortOrder.Ascending; + } + // Is the sort alphabetic or number? + public readonly bool Alphabetic; + + public ListViewItemComparer(int column, SortOrder order, bool alphabetic) + { + this.col = column; + this.order = order; + this.Alphabetic = alphabetic; + + } + public int Compare(object x, object y) + { + // Convert the items that must be compared into ListViewItem objects. + string listX = ((ListViewItem)x).SubItems[this.col].Text; + string listY = ((ListViewItem)y).SubItems[this.col].Text; + int val; + // Sort using the specified column and specified sorting type. + if (Alphabetic) + val = listX.CompareTo(listY); + else + { + if (int.Parse(listX) > int.Parse(listY)) + val = 1; + else if (int.Parse(listX) == int.Parse(listY)) + val = 0; + else + val = -1; + } + if (this.order == SortOrder.Ascending) + return val; + else + return val * -1; + } + } + } + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |