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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:49:11+00:00 2026-05-18T00:49:11+00:00

EXACT duplicate of Datagrid View Button repeat I have added button to datagrid view

  • 0

EXACT duplicate of Datagrid View Button
repeat

I have added button to datagrid view but when ever the function is called more than once then new button adds I need to stop this addition

  void AddtoGrid()
    {
        try
        {                
            table = new DataTable();
            bcol = new DataGridViewButtonColumn();
            bcol.HeaderText = "Action ";
            bcol.Text = "Delete";
            bcol.Name = "deleteUserButton";
            bcol.UseColumnTextForButtonValue = true;                

            table.Columns.Add("Name");
            table.Columns.Add("Type");
            table.Columns.Add("Status");
            table.Columns.Add("Date Created");


            for (int i = 0; i < userAction.UserName.ToArray().Length; i++)
            {
                row = table.NewRow();
                asc.Add(userAction.UserName[i]);
                row["Name"] = userAction.UserName[i];
                row["Type"] = userAction.UserType[i];
                row["Status"] = userAction.UserStatus[i];
                row["Date Created"] = userAction.DateCrea[i];
                table.Rows.Add(row);
            }

            UsersView.DataSource = table;
            UsersView.AllowUserToAddRows = false;//To remove extra row at the end
            UsersView.Columns.Add(bcol);
        }
        catch (Exception ca)
        {
            MessageBox.Show(ca.ToString());
        }
    }//End Function for Getting Present Users
  • 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-18T00:49:12+00:00Added an answer on May 18, 2026 at 12:49 am

    Split the method up in two:

    1.) To setup the grid structure
    2.) To add new rows

    public void SetupDataGridView()
    {
                table = new DataTable();
                bcol = new DataGridViewButtonColumn();
                bcol.HeaderText = "Action ";
                bcol.Text = "Delete";
                bcol.Name = "deleteUserButton";
                bcol.UseColumnTextForButtonValue = true;                
    
                table.Columns.Add("Name");
                table.Columns.Add("Type");
                table.Columns.Add("Status");
                table.Columns.Add("Date Created");
    
                UsersView.DataSource = table;
                UsersView.AllowUserToAddRows = false;//To remove extra row at the end
                UsersView.Columns.Add(bcol);
    }
    
    public void PopulateDataGridView()
    {
    
                for (int i = 0; i < userAction.UserName.ToArray().Length; i++)
                {
                    row = table.NewRow();
                    asc.Add(userAction.UserName[i]);
                    row["Name"] = userAction.UserName[i];
                    row["Type"] = userAction.UserType[i];
                    row["Status"] = userAction.UserStatus[i];
                    row["Date Created"] = userAction.DateCrea[i];
                    table.Rows.Add(row);
                }
    
    }
    

    And this is still a suboptimal approach, but that’s the most anyone can do for someone with your skills.

    You lack basic knowledge of programming and object oriented programming in particular. Get a book (e.g. chris sells’ book on windows forms programming) read it, and then come back. You will benefit from it!

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

Sidebar

Related Questions

This is more or less an exact duplicate of this post , but as
Exact duplicate of Function name for creating something if it's not there yet I
Closed as exact duplicate of How can I find the method that called the
Possibly a duplicate, but I couldn't find an exact answer to my problem searching
Possible Duplicate: Why does C# execute Math.Sqrt() more slowly than VB.NET? I'm running into
Writing a simple program that will find exact duplicate files on my computer, but
Closed as exact duplicate of this question . But reopened, as the other Singleton
Closed as exact duplicate of this question . I have an array/list of elements.
I found this post, which seems to be an exact duplicate, but I can't
Yes this is an exact duplicate of this question , but the link given

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.