Reputation: 329
another problem, this one I don't think is as simple as a double like it was last time.
I'm making a listbox that I only want the user to be able to select one option from, and for it change the 'selected state' of the other 2 that are right next to it on the form. The problem is, I can't figure out how to pull whats been selected in the first list box.
I've tried using
private void workshopSelect_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 1; i != 5; i++) {
if (workshopSelect.GetSelected == i){
NoDBox.SetSelected(i, true);
feeBox.SetSelected(i, true);
}
}
}
but the workshopselect.getselected has red squigglies. It says that the == operator cannot be used, and that it "Returns a value indicating whether the specified item is selected" I tried using (workshopSelect.GetSelected[i])
that didn't work, tried using (workshopSelect.GetSelected(i))
that didn't work either.
The program should look like this when I select one of the Workshop lines
So my question really is, just what exactly do I use to check the box for what line has been selected?
Upvotes: 0
Views: 96
Reputation: 329
The reason my if (workshopSelect.GetSelected(i))
did not work was because well.. I forgot one simple thing, figuring since it said that the == operator was not allowed (which it is). It was because I had to type it out like this if (workshopSelect.GetSelected(i) == true)
once I changed that, it did exactly what I wanted it to do.
Upvotes: 0
Reputation: 5488
You should use SelectedItem
property instead of GetSelected
to get selected item.
Or SelectedIndex
to get index.
if (listbox1.SelectedItem.ToString () == "Supervision skill")
...
if (listbox1.SelectedIndex == 1) ...
Upvotes: 1