How to set/build listview filterbar vs2019 winform C#

0

How do i apply/build listView filterbar with C# into vs2019

Need extended filter functionality listView-bar each column, as like using >,<,>=,=<, exist, between,,,.....etc. Filter with search and view Rows with filter condition.

[ListView Column Filter button and field not working...]

Please see images---link below...

https://ibb.co/2sLVrpD

https://ibb.co/hKdWRDn

Thank you in advanced.

What I have tried: https://drive.google.com/file/d/1Ui-e2SmY5nyv2vlc-loYv4RfLYbrTC0g/view?usp=sharing

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 Button button6;
            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 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.listViewFilter1 = new ListViewFilter.ListViewFilter();
                this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
                this.button6 = new System.Windows.Forms.Button();
                this.panel1.SuspendLayout();
                this.SuspendLayout();
                // 
                // panel1
                // 
                this.panel1.Controls.Add(this.button6);
                this.panel1.Controls.Add(this.button5);
                this.panel1.Controls.Add(this.button4);
                this.panel1.Controls.Add(this.textBox1);
                this.panel1.Controls.Add(this.button3);
                this.panel1.Controls.Add(this.button2);
                this.panel1.Controls.Add(this.button1);
                this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
                this.panel1.Location = new System.Drawing.Point(0, 0);
                this.panel1.Name = "panel1";
                this.panel1.Size = new System.Drawing.Size(87, 375);
                this.panel1.TabIndex = 0;
                // 
                // button5
                // 
                this.button5.FlatStyle = System.Windows.Forms.FlatStyle.System;
                this.button5.Location = new System.Drawing.Point(12, 152);
                this.button5.Name = "button5";
                this.button5.Size = new System.Drawing.Size(63, 20);
                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(13, 125);
                this.button4.Name = "button4";
                this.button4.Size = new System.Drawing.Size(63, 20);
                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(13, 97);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(63, 20);
                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(13, 69);
                this.button3.Name = "button3";
                this.button3.Size = new System.Drawing.Size(63, 20);
                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(13, 42);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(63, 20);
                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(13, 14);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(63, 20);
                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 = 85;
                // 
                // 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.Filtered = true;
                this.listViewFilter1.Location = new System.Drawing.Point(87, 0);
                this.listViewFilter1.Name = "listViewFilter1";
                this.listViewFilter1.ShadeColor = System.Drawing.Color.WhiteSmoke;
                this.listViewFilter1.Size = new System.Drawing.Size(409, 271);
                this.listViewFilter1.SortOrder = true;
                this.listViewFilter1.TabIndex = 1;
                this.listViewFilter1.UseCompatibleStateImageBehavior = false;
                this.listViewFilter1.View = System.Windows.Forms.View.Details;
                // 
                // button6
                // 
                this.button6.FlatStyle = System.Windows.Forms.FlatStyle.System;
                this.button6.Location = new System.Drawing.Point(13, 282);
                this.button6.Name = "button6";
                this.button6.Size = new System.Drawing.Size(63, 20);
                this.button6.TabIndex = 6;
                this.button6.Text = "Form";
                this.button6.Click += new System.EventHandler(this.button6_Click);
                // 
                // Form1
                // 
                this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                this.ClientSize = new System.Drawing.Size(629, 375);
                this.Controls.Add(this.listViewFilter1);
                this.Controls.Add(this.panel1);
                this.Name = "Form1";
                this.Text = "Test ListViewFilter Control";
                this.panel1.ResumeLayout(false);
                this.panel1.PerformLayout();
                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 ] = "";
    
        }
    
            private void button6_Click(object sender, EventArgs e)
            {
                Form frm = new Form2();
                frm.Show();
            }
        }
    }
   

Working with references ListViewFilter.

Win32Enum.cs using System;

    /// <summary>
    /// Win32 enumerations, flags, codes, values
    /// </summary>
    namespace ListViewFilter
    {
    
      /// <summary>
      /// Custom draw draw stage values
      /// </summary>
      public enum W32_CDDS : int
      {
        CDDS_PREPAINT         = 0x00000001,
        CDDS_POSTPAINT        = 0x00000002,
        CDDS_PREERASE         = 0x00000003,
        CDDS_POSTERASE        = 0x00000004,
        CDDS_ITEM             = 0x00010000,
        CDDS_ITEMPREPAINT     = ( CDDS_ITEM | CDDS_PREPAINT ),
        CDDS_ITEMPOSTPAINT    = ( CDDS_ITEM | CDDS_POSTPAINT ),
        CDDS_ITEMPREERASE     = ( CDDS_ITEM | CDDS_PREERASE ),
        CDDS_ITEMPOSTERASE    = ( CDDS_ITEM | CDDS_POSTERASE ),
        CDDS_SUBITEM          = 0x00020000,
        CDDS_SUBITEMPREPAINT  = ( CDDS_SUBITEM | CDDS_ITEMPREPAINT ),
        CDDS_SUBITEMPOSTPAINT = ( CDDS_SUBITEM | CDDS_ITEMPOSTPAINT ),
        CDDS_SUBITEMPREERASE  = ( CDDS_SUBITEM | CDDS_ITEMPREERASE ),
        CDDS_SUBITEMPOSTERASE = ( CDDS_SUBITEM | CDDS_ITEMPOSTERASE ),
      }
    
    
      /// <summary>
      /// Custom draw state information
      /// </summary>
      public enum W32_CDIS : int
      {
        CDIS_SELECTED         = 0x0001,
        CDIS_GRAYED           = 0x0002,
        CDIS_DISABLED         = 0x0004,
        CDIS_CHECKED          = 0x0008,
        CDIS_FOCUS            = 0x0010,
        CDIS_DEFAULT          = 0x0020,
        CDIS_HOT              = 0x0040,
        CDIS_MARKED           = 0x0080,
        CDIS_INDETERMINATE    = 0x0100,
        CDIS_SHOWKEYBOARDCUES = 0x0200
      }
    
    
      /// <summary>
      /// Custom draw return values
      /// </summary>
      public enum W32_CDRF : int
      {
        CDRF_DODEFAULT          = 0x0000,
        CDRF_NEWFONT            = 0x0002,
        CDRF_SKIPDEFAULT        = 0x0004,
        CDRF_NOTIFYPOSTPAINT    = 0x0010,
        CDRF_NOTIFYITEMDRAW     = 0x0020,
        CDRF_NOTIFYSUBITEMDRAW  = 0x0020, 
        CDRF_NOTIFYPOSTERASE    = 0x0040
      }
    
    
      /// <summary>
      /// GetWindowLong flags
      /// </summary>
      public enum W32_GWL : int
      {
        GWL_WNDPROC    = (-4),
        GWL_HINSTANCE  = (-6),
        GWL_HWNDPARENT = (-8),
        GWL_STYLE      = (-16),
        GWL_EXSTYLE    = (-20),
        GWL_USERDATA   = (-21),
        GWL_ID         = (-12)
      }
    
    
      /// <summary>
      /// Header control item format
      /// </summary>
      public enum W32_HDF : int
      {
        HDF_LEFT            = 0x0000,
        HDF_RIGHT           = 0x0001,
        HDF_CENTER          = 0x0002,
        HDF_JUSTIFYMASK     = 0x0003,
        HDF_NOJUSTIFY       = 0xFFFC,
        HDF_RTLREADING      = 0x0004,
        HDF_SORTDOWN        = 0x0200,
        HDF_SORTUP          = 0x0400,
        HDF_SORTED          = 0x0600,
        HDF_NOSORT          = 0xF1FF,
        HDF_IMAGE           = 0x0800,
        HDF_BITMAP_ON_RIGHT = 0x1000,
        HDF_BITMAP          = 0x2000,
        HDF_STRING          = 0x4000,
        HDF_OWNERDRAW       = 0x8000
      }
    
    
      /// <summary>
      /// Header control filter type 
      /// </summary>
      public enum W32_HDFT : int
      {
        HDFT_ISSTRING   = 0x0000,
        HDFT_ISNUMBER   = 0x0001,
        HDFT_HASNOVALUE = 0x8000
      }
    
    
      /// <summary>
      /// Header control item masks
      /// </summary>
      public enum W32_HDI : int
      {
        HDI_WIDTH      = 0x0001,
        HDI_HEIGHT     = HDI_WIDTH,
        HDI_TEXT       = 0x0002,
        HDI_FORMAT     = 0x0004,
        HDI_LPARAM     = 0x0008,
        HDI_BITMAP     = 0x0010,
        HDI_IMAGE      = 0x0020,
        HDI_DI_SETITEM = 0x0040,
        HDI_ORDER      = 0x0080,
        HDI_FILTER     = 0x0100
      }
    
    
      /// <summary>
      /// Header control styles
      /// </summary>
      public enum W32_HDS : int
      {
        HDS_HORZ      = 0x0000,
        HDS_BUTTONS   = 0x0002,
        HDS_HOTTRACK  = 0x0004,
        HDS_HIDDEN    = 0x0008,
        HDS_DRAGDROP  = 0x0040,
        HDS_FULLDRAG  = 0x0080,
        HDS_FILTERBAR = 0x0100
      }
    
    
      /// <summary>
      /// Header control hittest results
      /// </summary>
      public enum W32_HHT : int
      {
        HHT_NOWHERE        = 0x0001,
        HHT_ONHEADER       = 0x0002,
        HHT_ONDIVIDER      = 0x0004,
        HHT_ONDIVOPEN      = 0x0008,
        HHT_ONFILTER       = 0x0010,
        HHT_ONFILTERBUTTON = 0x0020,
        HHT_ABOVE          = 0x0100,
        HHT_BELOW          = 0x0200,
        HHT_TORIGHT        = 0x0400,
        HHT_TOLEFT         = 0x0800
      }
    
    
      /// <summary>
      /// ListView item masks
      /// </summary>
      public enum W32_LVIF : int
      {
        LVIF_TEXT        = 0x0001,
        LVIF_IMAGE       = 0x0002,
        LVIF_PARAM       = 0x0004,
        LVIF_STATE       = 0x0008,
        LVIF_INDENT      = 0x0010,
        LVIF_NORECOMPUTE = 0x0800
      }
    
    
      /// <summary>
      /// ListView item rectangle type
      /// </summary>
      public enum W32_LVIR : int
      {
        LVIR_BOUNDS        = 0x0000,
        LVIR_ICON          = 0x0001,
        LVIR_LABEL         = 0x0002,
        LVIR_SELECTBOUNDS  = 0x0003
      }
    
    
      /// <summary>
      /// ListView item states
      /// </summary>
      public enum W32_LVIS : int
      {
        LVIS_FOCUSED        = 0x0001,
        LVIS_SELECTED       = 0x0002,
        LVIS_CUT            = 0x0004,
        LVIS_DROPHILITED    = 0x0008,
        LVIS_ACTIVATING     = 0x0020,
        LVIS_OVERLAYMASK    = 0x0F00,
        LVIS_STATEIMAGEMASK = 0xF000
      }
    
    
    }

    

list of References:::

Win32Enum.cs

Win32Msgs.cs

Win32Struct.cs

c#
asked on Stack Overflow Sep 27, 2020 by IT_ • edited Sep 27, 2020 by IT_

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0