Reputation: 49
In datagridview, when we need to show value then it will display as below.
row1 >> User 1
row2 >> User 2
row3 >> User 3
I want to click user 1 and then appearing or pop up a new form (to show details) how do I manage it?
Upvotes: 0
Views: 41
Reputation: 3149
You can do it in many ways. I am showing an example how to selected rows value in another form with labels as follows:
In Form2, you have to create a second constructor that will take two objects :
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string yourName { get; set; }
public int Age { get; set; }
public Form2(string name, int age)
{
InitializeComponent();
yourName = name;
Age = age;
}
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = yourName;
label2.Text = Age.ToString();
}
}
In Form1, you create an Instance of Form2 and pass objects :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2("Jon Smith", 33);
this.Hide();
F2.ShowDialog();
}
}
Upvotes: 1