Assume datagridview which contains two column Name and Address.
Now in Name column there is lot of records Like Nims, john, kan, rocks, rita, etc...
Now if I am entering character 'K','A','N' then cell will be focus on kan.
I have google for this but I get solution as below code which didn't satisfied my question.
Because it is focus cell which contains pressed character as starting character of cell value.
Thanks in advance.
Code I have tried
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
}
}
}
}
{
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
}
}
}
}
Ravi SangtaniPosted Jul 7, 2017, 8:15 AM