Hello
I want to force call [ listBox1_SelectedIndexChanged] IN [ textBox1_KeyUp]
I want to force call [ listBox1_SelectedIndexChanged] IN [ textBox1_KeyUp]
C#:
namespace MyWinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{ // After textBox1_KeyUp text into the textbox, I try to force call listBox1_SelectedIndexChanged.
// listBox1_SelectedIndexChanged is private type.... I don't know this part.
listBox1.listBox1_SelectedIndexChanged(); //<=========== I want to force call [ listBox1_SelectedIndexChanged] IN [ textBox1_KeyUp]
}
private void textBox1_TextChanged(object sender, EventArgs e)
{ // I will enter text into the textbox.
listBox1.SelectedIndexChanged -= new EventHandler(listBox1_SelectedIndexChanged);
listBox1.SelectedIndex = idx;
listBox1.SetSelected(idx, true);
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int nIndex = listBox1.SelectedIndex;
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Apple");
listBox1.Items.Add("Banana");
listBox1.Items.Add("Coconut");
listBox1.Items.Add("Grape");
listBox1.SelectedIndex = 1;
}
}
}
Last edited: