Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I created dataGridView with 3 column connected using Linq to Sql. The all 3 columns are defined like dataGridViewTextColumn.

- - - - - - - - - - - - - - - - - - - - - - -'
First Name ' Last Name ' ---Date----' - Headers
-----------'-----------'--------------'
---John--- '--Green--'01.01.2013-- ' - Data
---Phil--- '--Muray---'02.01.2013--'
- - - - - - '- - - - - '- - - - - - - - - - - '

My problem is when I click one row from the dataGridView from windows form "Form1" to fill with data all 3 Textboxes(FirstNameTextbox, LastNameTextBox, DateTextBox) from windows form "Form2".
I'm using CellContentClick method but I don't have idea how to solve this problem.

XML
<pre lang="cs">private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           if (dataGridView1.CurrentCell.Value != null)
           {
                Form2 f2 = new Form2();
                f2.Show();
                ... no idea...
           }
        }</pre>

Thanks in advanced for your help.
Posted
Updated 26-Feb-13 1:36am
v2

1 solution

Create 3 properties in Form2 and create a parametrized constructor which will fill the value when you create the object of the Form2, or you can directly assign the value to TextBoxes in constructor.

Form2:

C#
public Form2(string _firstName, string _lastName, DateTime _date)
        {
            InitializeComponent();
            textBox1.Text = _firstName;
            textBox2.Text = _lastName;
            textBox3.Text = _date.ToShortDateString();
        }



Form1:

Form2 frm = new Form2("first", "second", System.DateTime.Now);
            frm.Show();
 
Share this answer
 
Comments
zabamkd 26-Feb-13 12:04pm    
Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900