|
-
Apr 19th, 2008, 09:33 AM
#1
Thread Starter
Hyperactive Member
[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;
}
}
}
-
Apr 19th, 2008, 10:07 AM
#2
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;
}
}
-
Apr 19th, 2008, 02:04 PM
#3
Thread Starter
Hyperactive Member
Re: C#/VS2005 - How can I pass a listbox and it's selected index?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|