hi everyone,
i am creating a project where i populate a datagridview, this datagridview has various rows and columns like c1,c2,c3,c4,c5. However i would like that when i keypress my datagridview along any of the populated rows, i want to be able to carry only the value of c1(column1) to textbox1 irrespective of which column of the row is highlighted when i keypress on the datagridview
any help will be of great help.
thanks again and Best Regards
Loading

Sudhakar ChaudharyPosted Mar 18, 2012, 1:08 PM
{
try
{
//add column to datagridvew
dataGridView1.Columns.Add("", "C1");
dataGridView1.Columns.Add("", "C2");
//filling datagridview
SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress; Initial Catalog=samflin; ;Integrated Security=True;");
SqlDataAdapter da = new SqlDataAdapter("select * from mytable", con);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
int row = ds.Tables["Emp"].Rows.Count - 1;
for (int r = 0; r <= row; r++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
}
}
catch (Exception ms) { }
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
}
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
}
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
}
}
you can also see the attached file.
hope this can help you.
Jignesh TrivediPosted Mar 19, 2012, 1:00 AM
Same thing you can achieve using java script
down load attachment and rename it .zip to .zipx
hope this help.