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

  • Home
  • SEARCH
  • 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 612771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:55:44+00:00 2026-05-13T17:55:44+00:00

I’ve created custom column(DataGridViewButtonControlColumn) and cell(ButtonControlCell) classes to hold System.Windows.Forms.Button controls. The buttons get

  • 0

I’ve created custom column(DataGridViewButtonControlColumn) and cell(ButtonControlCell) classes to hold System.Windows.Forms.Button controls. The buttons get added to the columns and get displayed properly.
Before I set the button as the value of a ButtonControlCell, I attach an event handler for “Click”. But this handler is not called when a button is clicked.

I add the button to the DataGridView’s controls in the overridden Paint function.

Are there any specific steps which I have to follow to register the Button with the DataGridView?

Code:

public class ButtonControlCell : DataGridViewTextBoxCell
    {
.
.
.
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            if (btnVal != null)
            {
                btnVal.Size = new System.Drawing.Size(80, 20);
                btnVal.Location = cellBounds.Location;
                this.DataGridView.Controls.Add(btnVal);
            }            
        }
.
.
.
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
        {
            // This is not called when the button is clicked (which is correct I guess)
            base.OnMouseClick(e);

            if (btnVal != null)
            {
                btnVal.PerformClick();
            }
        }
.
.
}

In the implementation:

private void AddButtonCell(string sText, EventHandler oEh, DataGridViewButtonColumn oClm, DataGridView dgvParent, int iRow, int iColumn)
        {
            Button btnTemp = new Button();
            btnTemp.Height = 20;
            btnTemp.Width = 60;
            btnTemp.Anchor = AnchorStyles.Top;
            btnTemp.Text = sText;
            btnTemp.Click += new EventHandler(btnTemp_Click);
            btnTemp.Tag = new Point(iRow, iColumn);

            Controls.Add(btnTemp);

            dgvParent.Rows[iRow].Cells[iColumn].Value = btnTemp;
        }

        void btnTemp_Click(object sender, EventArgs e)
        {
            Button btnSender = (Button)sender;

            DataGridViewRow r = dgvResults.Rows[((Point)btnSender.Tag).X];

            TagInfo oRet = new TagInfo((string)r.Cells[iTitleColIndex].Value, (string)r.Cells[iArtistColIndex].Value,
                (string)r.Cells[iAlbumColIndex].Value);
            oRet.imgAlbumArt = (System.Drawing.Image)r.Cells[iArtColIndex].Tag;
            oParent.TagWithInfo(oRet, true);
        }
  • 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-13T17:55:45+00:00Added an answer on May 13, 2026 at 5:55 pm

    The method used to achieve this is to catch an event (e.g. button click) performed on the DataGrid, get the control and perform any additional tasks depending on that.
    Found the answer by going through several tutorials on custom DataGridView s.

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

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer i would probably write the query similar to: select *,… May 15, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer This may be helpful to you. function checkTextboxNotFilled(txtboxid) { var… May 15, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer If you remove the cycle plugin code, you'll see that… May 15, 2026 at 2:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.