Add Row To Datagridview From Another Form In C#

How to Add a New Row To Datagridview From Another Form Using C#

Add Row To Datagridview From Another Form Using C#


In This C# Tutorial We Will See How To Insert A New Row To a Datagridview With Data From TextBoxes In Another Form Using C# Windows Form and Visual Studio Editor .

WATCH THIS C# TUTORIAL


Project Source Code:


// ------ First Create a Form  Where You Put The Datagridview 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Csharp_Tutorials.rst
{
    public partial class FRM_GRIDVIEW : Form
    {
        public FRM_GRIDVIEW()
        {
            InitializeComponent();
        }

// button to open the form where the textboxes are in
        private void button_NewForm_Click(object sender, EventArgs e)
        {
            FormINFO finfo = new FormINFO(this);
            finfo.Show();
        }
    }
}


Datagridview Form



// ------ Create a Form With TextBoxes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Csharp_Tutorials.rst
{
    public partial class FormINFO : Form
    {
        FRM_GRIDVIEW fgrid;
        public FormINFO(FRM_GRIDVIEW fg)
        {
            InitializeComponent();
            this.fgrid = fg;
        }

// button to add the row with the data to the datagridview
        private void button_Add_Click(object sender, EventArgs e)
        {
            fgrid.dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text);
        }

    }
}


TextBoxes Form



 - Watch The Video Tutorial To See The Scond Method ( making the datagrdivew static ) 



OUTPUT:


C# - Insert Row To Datagridview From Another Form





Share this

Related Posts

Previous
Next Post »

3 comments

comments
3 avril 2023 à 21:56 delete Ce commentaire a été supprimé par l'auteur.
avatar
11 mars 2024 à 23:40 delete

not working ......datagridview error

Reply
avatar