using System; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public static List<employee> lst = new List<employee>(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { employee p = new employee(); p.eid = Convert.ToInt32(textBox1.Text); p.ename = textBox2.Text; p.edes = textBox3.Text; Form2 form2 = new Form2(); form2.passThisValuetoDgv(p.eid, p.ename, p.edes); form2.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { employee p = new employee(); p.eid = Convert.ToInt32(textBox1.Text); p.ename = textBox2.Text; p.edes = textBox3.Text; lst.Add(p); dataGridView1.DataSource = lst; } } public class employee { public int eid { get; set; } public string ename { get; set; } public string edes { get; set; } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } DataTable dt; public void passThisValuetoDgv(int value1, string value2,string value3) { dt = new DataTable(); dt.Columns.Add("Col1"); dt.Columns.Add("Col2"); dt.Columns.Add("Col3"); dataGridView1.DataSource = dt; dt.Rows.Add(value1); dataGridView1.CurrentRow.Cells[1].Value = value2; dataGridView1.CurrentRow.Cells[2].Value = value3; } } }
dt.Rows.Add(value1); dataGridView1.CurrentRow.Cells[1].value = value2; dataGridView1.CurrentRow.Cells[2].value = value3;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)