index += 1 equals index + 2 ? [modified]
-
private void ComboBox_KeyDown(object sender, KeyEventArgs e)
{
this.ComboBox.DroppedDown = true;
if (e.KeyCode == Keys.Up && this.ComboBox.SelectedIndex != 0)
{
this.ComboBox.SelectedIndex -= 1;
return;
}
if (e.KeyCode == Keys.Down && this.ComboBox.SelectedIndex != this.ComboBox.Items.Count - 1)
{
this.ComboBox.SelectedIndex += 1;
return;
}
this.ComboBox.SelectedItem = this.ComboBox.Text + "%";
}Hello folks. I have this event set up to search/skip to the contents of a ComboBox by the text entered, however I want to make sure I can still use the up and down keys functionality... My problem is when I run this code in my project and press the up or down keys in the ComboBox my selection moves up or down two spaces rather than one. What am I missing? Thanks in advance! EDIT: Sorry, the code actually was slightly wrong due to my experimenting before posting. It's fixed how I meant it to be and the problem persists. The old code was as follows and has the same outcome:
private void ComboBox_KeyDown(object sender, KeyEventArgs e)
{
this.ComboBox.DroppedDown = true;
if (e.KeyCode == Keys.Up && this.ComboBox.SelectedIndex != 0)
{
this.ComboBox.SelectedIndex = this.ComboBox.SelectedIndex - 1;
return;
}
if (e.KeyCode == Keys.Down && this.ComboBox.SelectedIndex != this.ComboBox.Items.Count - 1)
{
this.ComboBox.SelectedIndex = this.ComboBox.SelectedIndex + 1;
return;
}
this.ComboBox.SelectedItem = this.ComboBox.Text + "%";
}modified on Wednesday, February 25, 2009 6:10 PM
-
private void ComboBox_KeyDown(object sender, KeyEventArgs e)
{
this.ComboBox.DroppedDown = true;
if (e.KeyCode == Keys.Up && this.ComboBox.SelectedIndex != 0)
{
this.ComboBox.SelectedIndex -= 1;
return;
}
if (e.KeyCode == Keys.Down && this.ComboBox.SelectedIndex != this.ComboBox.Items.Count - 1)
{
this.ComboBox.SelectedIndex += 1;
return;
}
this.ComboBox.SelectedItem = this.ComboBox.Text + "%";
}Hello folks. I have this event set up to search/skip to the contents of a ComboBox by the text entered, however I want to make sure I can still use the up and down keys functionality... My problem is when I run this code in my project and press the up or down keys in the ComboBox my selection moves up or down two spaces rather than one. What am I missing? Thanks in advance! EDIT: Sorry, the code actually was slightly wrong due to my experimenting before posting. It's fixed how I meant it to be and the problem persists. The old code was as follows and has the same outcome:
private void ComboBox_KeyDown(object sender, KeyEventArgs e)
{
this.ComboBox.DroppedDown = true;
if (e.KeyCode == Keys.Up && this.ComboBox.SelectedIndex != 0)
{
this.ComboBox.SelectedIndex = this.ComboBox.SelectedIndex - 1;
return;
}
if (e.KeyCode == Keys.Down && this.ComboBox.SelectedIndex != this.ComboBox.Items.Count - 1)
{
this.ComboBox.SelectedIndex = this.ComboBox.SelectedIndex + 1;
return;
}
this.ComboBox.SelectedItem = this.ComboBox.Text + "%";
}modified on Wednesday, February 25, 2009 6:10 PM
Well now I feel stupid. But I guess it's the learning process. Turns out the built-in up/down key functionality was still running, so I essentially was repeating the process with redundant code. Removing the redundant code and leaving the return function to prevent the pseudo-search function on up/down works fine. Thanks to anyone who read and considered this. EDIT: Hahaha! Now I think I just realized this entire process was useless since the up/down keys don't act any differently without the extra code. I need more sleep, maybe? Someone put me out of my misery! :laugh:
-
Well now I feel stupid. But I guess it's the learning process. Turns out the built-in up/down key functionality was still running, so I essentially was repeating the process with redundant code. Removing the redundant code and leaving the return function to prevent the pseudo-search function on up/down works fine. Thanks to anyone who read and considered this. EDIT: Hahaha! Now I think I just realized this entire process was useless since the up/down keys don't act any differently without the extra code. I need more sleep, maybe? Someone put me out of my misery! :laugh:
ps.
index += 1
equalsindex = index + 1
:) -
ps.
index += 1
equalsindex = index + 1
:)