Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3401040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:58:00+00:00 2026-05-18T04:58:00+00:00

I’m using .NET 3.5, C#, and WinForms. My grid has lots of columns: SellerName,

  • 0

I’m using .NET 3.5, C#, and WinForms.

My grid has lots of columns: SellerName, BuyerName, LoadType, LoadName, DriverName, CarSerialNumber, etc. I want to filter the BindingSource. I did this using ComboBoxes which is filled on DropDown with the grid cells’ values, but it’s not practical and makes for a bad-looking form.

I need advice on what is the best way to let the user choose values of the grid and then filter with a button. Can I make it like in Excel? There is a button on the column header, and when the user presses it, it shows a little menu with a checked list box. When the user checks any values and press a button it begins filtering.

Please advise me something.

This is pic of Excel:

Screenshot

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:58:01+00:00Added an answer on May 18, 2026 at 4:58 am

    Well,
    first of all you should create your custom filter usercontrol, as similar as you wish to the one in excel.

    Secondly, it’s not easy to do, but you could add filter buttons to the grid (simply doing grid.Controls.Add(...)) and keep them aligned with columns’ headers by overriding OnColumnWidthChanged/OnColumnHeadersHeightChanged of DatagridView.

    Finally, when user clicks on filter button, you can open a ToolStripDropDown with your custom filter embedded in it, I mean something similar to this answer (obviously with your control instead of the listview):
    DropDown Menu with ScrollBar in .NET


    EDIT:

    Here’s a (working) code sample:

    Custom Column Header Cell Class:

    public class DataGridFilterHeader : DataGridViewColumnHeaderCell
    {
        PushButtonState currentState = PushButtonState.Normal;
        Point cellLocation;
        Rectangle buttonRect;
    
        public event EventHandler<ColumnFilterClickedEventArg> FilterButtonClicked;
    
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds,
                                      Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates dataGridViewElementState,
                                      object value,
                                      object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds,
                       cellBounds, rowIndex,
                       dataGridViewElementState, value,
                       formattedValue, errorText,
                       cellStyle, advancedBorderStyle, paintParts);
    
            int width = 20; // 20 px
            buttonRect = new Rectangle(cellBounds.X + cellBounds.Width - width, cellBounds.Y, width, cellBounds.Height);
    
            cellLocation = cellBounds.Location;
            // to set image/ or some other properties to the filter button look at DrawButton overloads
            ButtonRenderer.DrawButton(graphics,
                                      buttonRect,
                                      "F",
                                      this.DataGridView.Font,
                                      false,
                                      currentState);
        }
    
        protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
        {
            if (this.IsMouseOverButton(e.Location))
                currentState = PushButtonState.Pressed;
            base.OnMouseDown(e);
        }
        protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
        {
            if (this.IsMouseOverButton(e.Location))
            {
                currentState = PushButtonState.Normal;
                this.OnFilterButtonClicked();
            }
            base.OnMouseUp(e);
        }
        private bool IsMouseOverButton(Point e)
        {
            Point p = new Point(e.X + cellLocation.X, e.Y + cellLocation.Y);
            if (p.X >= buttonRect.X && p.X <= buttonRect.X + buttonRect.Width &&
                p.Y >= buttonRect.Y && p.Y <= buttonRect.Y + buttonRect.Height)
            {
                return true;
            }
            return false;
        }
        protected virtual void OnFilterButtonClicked()
        {
            if (this.FilterButtonClicked != null)
                this.FilterButtonClicked(this, new ColumnFilterClickedEventArg(this.ColumnIndex, this.buttonRect));
        }
    }
    

    Custom Event Args:

    public class ColumnFilterClickedEventArg : EventArgs
    {
        public int ColumnIndex { get; private set; }
        public Rectangle ButtonRectangle { get; private set; }
        public ColumnFilterClickedEventArg(int colIndex, Rectangle btnRect)
        {
            this.ColumnIndex = colIndex;
            this.ButtonRectangle = btnRect;
        }
    }
    

    DataGridView Override:

    public class DataGridWithFilter : DataGridView
    {
        protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
        {
            var header = new DataGridFilterHeader();
            header.FilterButtonClicked += new EventHandler<ColumnFilterClickedEventArg>(header_FilterButtonClicked);
            e.Column.HeaderCell = header;
            base.OnColumnAdded(e);
        }
    
        void header_FilterButtonClicked(object sender, ColumnFilterClickedEventArg e)
        {
            // open a popup on the bottom-left corner of the
            // filter button
            // here's we add a simple hello world textbox, but you should add your filter control
            TextBox innerCtrl = new TextBox();
            innerCtrl.Text = "Hello World !";
            innerCtrl.Size = new System.Drawing.Size(100, 30);
    
            var popup = new ToolStripDropDown();
            popup.AutoSize = false;
            popup.Margin = Padding.Empty;
            popup.Padding = Padding.Empty;
            ToolStripControlHost host = new ToolStripControlHost(innerCtrl);
            host.Margin = Padding.Empty;
            host.Padding = Padding.Empty;
            host.AutoSize = false;
            host.Size = innerCtrl.Size;
            popup.Size = innerCtrl.Size;
            popup.Items.Add(host);
    
            // show the popup
            popup.Show(this, e.ButtonRectangle.X, e.ButtonRectangle.Bottom);
        }
    }
    

    Result:

    Filter Image


    EDIT 2:

    Here’s a full VS2008 project sample (DataGrid with customized filter, not just “Hello World”): –> http://www.mediafire.com/?s6o8jmpzh0t82v2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.