📄 testlistviewfilter.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TestListViewFilter
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private ListViewFilter.ListViewFilter listViewFilter1;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.ToolTip toolTip1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.toolTip1.SetToolTip( this.button1, "Create some items to test" );
this.toolTip1.SetToolTip( this.button2, "Toggle filters mode" );
this.toolTip1.SetToolTip( this.button3, "Get the filter data of the sorted column" );
this.toolTip1.SetToolTip( this.button4, "Set the filter for the sorted column" );
this.toolTip1.SetToolTip( this.button5, "Set default format and alignment" );
this.toolTip1.SetToolTip( this.textBox1, "Text from/for the sorted column filter" );
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel1 = new System.Windows.Forms.Panel();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.listViewFilter1 = new ListViewFilter.ListViewFilter();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button5,
this.button4,
this.textBox1,
this.button3,
this.button2,
this.button1});
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(105, 211);
this.panel1.TabIndex = 0;
//
// button5
//
this.button5.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button5.Location = new System.Drawing.Point(15, 175);
this.button5.Name = "button5";
this.button5.TabIndex = 5;
this.button5.Text = "Reset";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button4
//
this.button4.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button4.Location = new System.Drawing.Point(16, 144);
this.button4.Name = "button4";
this.button4.TabIndex = 4;
this.button4.Text = "Set";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 112);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(75, 22);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "(filter value)";
//
// button3
//
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button3.Location = new System.Drawing.Point(16, 80);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "Get";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button2.Location = new System.Drawing.Point(16, 48);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Filters";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(16, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Populate";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// columnHeader1
//
this.columnHeader1.Text = "Strings";
this.columnHeader1.Width = 81;
//
// columnHeader2
//
this.columnHeader2.Text = "Numbers";
this.columnHeader2.Width = 80;
//
// columnHeader3
//
this.columnHeader3.Text = "Dates";
this.columnHeader3.Width = 100;
//
// listViewFilter1
//
this.listViewFilter1.AllowColumnReorder = true;
this.listViewFilter1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listViewFilter1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listViewFilter1.Filtered = true;
this.listViewFilter1.Location = new System.Drawing.Point(105, 0);
this.listViewFilter1.Name = "listViewFilter1";
this.listViewFilter1.ShadeColor = System.Drawing.Color.WhiteSmoke;
this.listViewFilter1.Size = new System.Drawing.Size(287, 211);
this.listViewFilter1.SortOrder = true;
this.listViewFilter1.TabIndex = 1;
this.listViewFilter1.View = System.Windows.Forms.View.Details;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(392, 211);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listViewFilter1,
this.panel1});
this.Name = "Form1";
this.Text = "Test ListViewFilter Control";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
listViewFilter1.BeginUpdate();
listViewFilter1.Items.Clear();
ListViewItem i;
i = listViewFilter1.Items.Add( "AB" );
i.SubItems.Add( "5.3" );
i.SubItems.Add( "Jan 29, 1958" );
i = listViewFilter1.Items.Add( "abc" );
i.SubItems.Add( "2" );
i.SubItems.Add( "April 15, 2003" );
i = listViewFilter1.Items.Add( "BCDE" );
i.SubItems.Add( "15.25" );
i.SubItems.Add( "Dec 31, 1999" );
i = listViewFilter1.Items.Add( "CDE" );
i.SubItems.Add( "12" );
i.SubItems.Add( "Mar 15, 0012" );
listViewFilter1.EndUpdate();
}
private void button2_Click(object sender, System.EventArgs e)
{
listViewFilter1.Filtered = !listViewFilter1.Filtered;
}
private void button3_Click(object sender, System.EventArgs e)
{
textBox1.Text = listViewFilter1.Header.Filter[ listViewFilter1.SortColumn ];
}
private void button4_Click(object sender, System.EventArgs e)
{
listViewFilter1.Header.Filter[ listViewFilter1.SortColumn ] = textBox1.Text;
}
private void button5_Click(object sender, System.EventArgs e)
{
listViewFilter1.SortColumn = 0;
listViewFilter1.SortOrder = true;
listViewFilter1.Filtered = true;
listViewFilter1.Header.DataType[ 0 ] = ListViewFilter.LVFDataType.String;
listViewFilter1.Header.DataType[ 1 ] = ListViewFilter.LVFDataType.Number;
listViewFilter1.Header.DataType[ 2 ] = ListViewFilter.LVFDataType.Date;
listViewFilter1.Header.Alignment[ 0 ] = HorizontalAlignment.Left;
listViewFilter1.Header.Alignment[ 1 ] = HorizontalAlignment.Right;
listViewFilter1.Header.Alignment[ 2 ] = HorizontalAlignment.Center;
listViewFilter1.Header.Filter[ 0 ] = "";
listViewFilter1.Header.Filter[ 1 ] = "";
listViewFilter1.Header.Filter[ 2 ] = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -