You are on page 1of 1

private void WorkerWisedataGridView1_KeyUp(object sender, KeyEventArgs e) { int i; i = e.KeyValue; //MessageBox.Show(i.ToString()); if (i == 112) { Form3 obj = new Form3(); obj.Show(); obj.groupBox2.

Visible = true; //obj.groupBox1.Visible = true; } else if (i == 114) { Form3 obj = new Form3(); obj.Show(); //obj.groupBox1.Visible=false; obj.groupBox2.Visible = true; } else if (i == 115) { MachineWisedataGridView1.Visible = true; } } ================================================================ If the DataGridView is databound then you can use the Find method on the Binding Source. If the grid isn't databound then you will have to write some code that manually loops through the rows looking for your data. Using the BindingSource.Find method will return you a row index. Use that value and set the DataGridView's CurrentCell like so: dataGridView1.CurrentCell = DataGridView1.Rows[rowIndexFromFind].Cells[0]; ============================================================== private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsLetter(e.KeyChar)) { for (int i = 0; i < (dataGridView1.Rows.Count); i++) { if (dataGridView1.Rows[i].Cells["Name"].Value.ToString().StartsWith( e.KeyChar.ToString(), true, CultureInfo.InvariantCulture)) { dataGridView1.Rows[i].Cells[0].Selected = true; return; // stop looping } } } }

You might also like