Reputation: 13206
How would I get the value of a cell that is clicked on and transfer it onto a second form?
This is my code so far:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
var form2 = new Form2();
this.Hide();
form2.Show();
}
}
Upvotes: 0
Views: 46
Reputation: 9322
Change the constructor of the form that would receive value, like:
public Form2(String passCellValue)
{
InitializeComponent();
}
Then call like this:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
String cellValue;
cellValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
var form2 = new Form2(cellValue);
this.Hide();
form2.Show();
}
}
Upvotes: 1
Reputation: 5798
Its very easy
private void gridAgentDetails_Click(object sender, EventArgs e) { for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++) { string str = gridAgentDetails.Text; }}
plaese check link
How to get column value of grid in C# Windows application?
and to transfer data , you can make general property or variable. Please check this link.
Upvotes: 0