Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Please see images---link below...
https://ibb.co/2sLVrpD
https://ibb.co/hKdWRDn

[ListView Column Filter button and field not working...]
Thank you in advanced.


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


What I have tried:

ListViewFilter_src.zip - Google Drive[^]
Posted
Updated 27-Sep-20 1:33am
v5
Comments
Richard MacCutchan 27-Sep-20 6:34am    
What exactly is the problem?
IT_i 27-Sep-20 6:50am    
ListView Column Filter button and field not working...
Please see images---link below...
https://ibb.co/2sLVrpD
https://ibb.co/hKdWRDn
Richard MacCutchan 27-Sep-20 7:09am    
Sorry, but if you want help then you need to provide full details of your problem in the question. And saying, "not working", is no help at all; we cannot guess what that could mean.
IT_i 27-Sep-20 7:13am    
Now my side Columns Filter icon and filter box click not working.
Project Link:
https://drive.google.com/file/d/1Ui-e2SmY5nyv2vlc-loYv4RfLYbrTC0g/view?usp=sharing
Richard MacCutchan 27-Sep-20 7:33am    
The person who wrote the article (ListViewFilter Control for .NET[^]) has not been active here for more than 15 years. So it is unlikely that you will get much assistance with this.

So you found some (old) code at: [^] for a very complex sub-classed ListView that makes heavy use of the Win API.

Now, you want us to wade into it, and add new features ? And, all you have done is look at the source-code ?

Here are your solutions:

0 study the Control and figure out how to add new features.

1 research CP and StackOverFlow for other, newer, articles on sorting the ListView, or other custom controls.

2 hire a programmer.
 
Share this answer
 
v2
I'm not downloading random zip files, nor would I wade through your whole code looking for the relevant parts if I did.
I don't follow link shorteners either: you never know where you will end up, or what you will find there.

If you want help, describe your problem in detailed English, post relevant fragments of your code and explain what it does that you didn't expect, or didn't do that you did.

Think about what you are asking: remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So if you tell us "it's not working" that means nothing to us: we have no idea what you expected it to do, or any way to run your code and find out what it actually did.

Asking questions is a skill and it's worth you learning how to do that. There is nowhere near enough information here for us to begin to help you - we have no idea what you are trying to do, or where you are starting from.

We don't even have any idea where you are stuck, or what help you might need - and that's kinda important, don't you think?

Start here: Asking questions is a skill[^] and think about what you need to know, and what you need to tell us in order to get help.

Then help us to help you!
 
Share this answer
 
Comments
BillWoodruff 27-Sep-20 7:28am    
fyi: your response was posted while i was writing mine :)
OriginalGriff 27-Sep-20 7:47am    
And yours deserved the upvote I just gave it - you actually looked at "his" code? "You're a better man than I am, Gunga Din!"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900