Tayyab Jatoi

Tayyab Jatoi

  • NA
  • 135
  • 26.6k

Listbox KeyDown event is not getting Execute

Dec 21 2018 11:55 PM
I have setup that when i press Keydown on  itemValueTxt(TextBox Name) it should focus on on my listbox which i name as itemListShow on index 0 and than i create this method itemListShow_KeyDown and i want to go through all items on itemListShow.
BUT
the problem is that after execution of  itemValueTxt_KeyDown method the control is not moving at all to this method itemListShow_KeyDown.there is not erroe appearing the control remain only on 0 Index not moving to next items
Please help me to know what i really missing. 
 
private void itemValueTxt_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
itemListShow.Focus();
itemListShow.SelectedIndex = 0;
}
}
private void itemListShow_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
this.itemListShow.SelectedIndex = this.itemListShow.SelectedIndex;
}
if (e.KeyCode == Keys.Up)
{
this.itemListShow.SelectedIndex = this.itemListShow.SelectedIndex;
}
}

Answers (2)