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 8010681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:48:49+00:00 2026-06-04T18:48:49+00:00

I have a DataGridView object: dataGridView1.DataSource = an.peaks; (an.peaks is a List<Point> object. Point

  • 0

I have a DataGridView object:

dataGridView1.DataSource = an.peaks;

(an.peaks is a List<Point> object. Point type has 3 properties: x,y,z)

witch generates the next table on run-time: (Apparently I cant upload an Image yet because I’m a new user so I’ll try to draw it 🙂

____|_x__|_y__|_z__|[new column ]
____|_11_|_12_|_13_|[text/button] <==\
____|_20_|_30_|_40_|[text/button] <== } Add text if something or button if something else.
____|_50_|_60_|_70_|[text/button] <==/

I would like to add buttons (as shown in the image/drawing) in a new column to each row that satisfying some condition. If the condition is not satisfied add some text instead.

Example: If the point already exist in the database show it’s substance name (each point represent a substance). If not add a button “ADD” to the corresponding row that will add the new point to the database.

The conditions are not the problems – they are only for examples. The problem is adding the buttons/text to each row and the clicking event for the new button/s.

  • 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-06-04T18:48:50+00:00Added an answer on June 4, 2026 at 6:48 pm

    This is actually quite simple to do using the DataGridView. What you need to do is:

    Add column of type DataGridViewButtonColumn

    DataGridViewButtonColumn is a standard DataGridView column type. It can be added through the designer but I generally prefer using code (usually in the form constructor).

    DataGridViewButtonColumn col = new DataGridViewButtonColumn();
    col.UseColumnTextForButtonValue = True;
    col.Text = "ADD";
    col.Name = "MyButton";
    dataGridView1.Columns.Add(col);
    

    Setting UseColumnTextForButtonValue true means that the Text property gets applied to all buttons giving them the “ADD” button text. You can also use DataPropertyName to point at a column in the grid’s datasource to provide the button text, or you can even set each cell’s value directly.

    Change buttons to text

    Once you have your button column you then want to turn particular buttons to text. You do this by replacing a cell of button type with one of text type. You can do this many places but one of the best is in the DataBindingComplete event handler – this event fires once the grid is bound and ready to display but before it is painted.

    Below I simply grab the row with index 1 but you can also inspect each rows Value property.

    void dataGridView1_DataBindingComplete(object sender,
        DataGridViewBindingCompleteEventArgs e)
    {
        dataGridView1.Rows[1].Cells["MyButton"] = new DataGridViewTextBoxCell();
    }
    

    Respond to button clicks

    The final part of the problem is responding to button clicks. This is a little bit cludgy – you need to either use the CellClick event or the EditingControlShowing event for the entire grid.

    • CellClick

      private void DataGridView1_CellClick(object sender,
          System.Windows.FormsDataGridViewCellEventArgs e) 
      { 
          if (DataGridView1.Columns[e.ColumnIndex].Name == "MyButton") 
          { 
              // button clicked - do some logic
          } 
      }
      
    • EditingControlShowing

      void dataGridView1_EditingControlShowing(object sender,
           DataGridViewEditingControlShowingEventArgs e)
      {
          if (e.Control is Button)
          {
              Button btn = e.Control as Button;
              btn.Click -= new EventHandler(btn_Click);
              btn.Click += new EventHandler(btn_Click);
          }
      }
      
      void btn_Click(object sender, EventArgs e)
      {
          int col = this.dataGridView1.CurrentCell.ColumnIndex;
          int row = this.dataGridView1.CurrentCell.RowIndex;
          // Rest of the logic goes here!
      } 
      

    In your case the editing control approach is probably best since it won’t respond to clicking on buttons that have been replaced with text. Also this way is more like how you respond to any other button on a form.

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

Sidebar

Related Questions

My app has a DataGridView object and a List of type MousePos. MousePos is
I have a DataGridView whose datasource is a BindingList. MyObj has a few nullable
I have a DataGridView with its datasource set to a generic list of custom
I have a form with datagridview and a List like this: private void Form1_Load(object
I have a List of an object, set to DataSource of a BindingSource, set
I have a datagridview which we will call dataGridViewExample. My object (the uncommon datatypes
I have a DataGridView that is bound to a list of objects called BaseChange.
I have DataGridView and I set DataSource of datagridview by using DataTables. DataTable dt
I have a datagridview bound to a datasource, and in each row in the
I have a DataGridView that displays a list of MMS Messages. To differentiate between

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.