[RESOLVED] C#/VS2005 - How can I pass a listbox and it's selected index?
I want to pass the selected index to a method. I have several listbox's and I want to figure out how I can pass that particular listbox's selected index to a method and then return some result. Not sure if I want it to just be a boolean or a number. I am thinking a boolean value would suffice.
checkDialsPosition(listbox1.SelectedIndex);
private void checkDialsPosition(chckthis listbox)
{
if (chckthis.SelectedIndex == 1)
{
if (dialPosition > 34 & dialPosition < 72)
{
pictureBox1.BackColor = Color.Green;
return true;
}
else { pictureBox1.BackColor = Color.Red;
return false;
}
}
}
Re: C#/VS2005 - How can I pass a listbox and it's selected index?
I'm not sure I entirely understand your question. You can just pass your method the SelectedIndex and do what you like. However, you are trying to pass your method an Integer when it is expecting a ListBox.
c# Code:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(CheckDialsPosition(this.listBox1.SelectedIndex).ToString());
}
private bool CheckDialsPosition(int selIndex)
{
if (selIndex == 1)
{
return true;
}
else
{
return false;
}
}
Re: C#/VS2005 - How can I pass a listbox and it's selected index?