4
Answers

my data grid view dosent updated

amr

amr

12y
2.5k
1
i have 2 forms one of them is my main form where my datagridview is,and the second form where my textbox is ,and i need to make any input on the textbox shows in my datagridview but it didnot appear

here is my form1 code


namespace datatabl
{
    public partial class Form1 : Form
    {
       
        DataTable customers =new DataTable();

        public Form1()

        {
            InitializeComponent();
            create();
            dataGridView1.DataSource = customers;
        }

        private void create()

         {
   
            customers.Columns.Add("FirstName", typeof(string));
            customers.Columns.Add("LastName", typeof(string));
         }


        public void addrows(string firstname,string lastname)
        {
            customers.Rows.Add(firstname, lastname);

        }
          
        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            Form2 d = new Form2();
            d.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
           
        }



    }
}


and my second form code is

namespace datatabl
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

     

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f.addrows(textBox1.Text, textBox2.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}




Answers (4)