Select only one item amidst two listboxes

Asked

Viewed 59 times

0

Oops! Guys, I wanted to select only one item in the middle of two listboxes, imagining the listbox as a radiobutton, if I select an item in one, it is no longer selected in the other. I tried so:

private void listBoxQuestoesObjetivas_SelectedIndexChanged(object sender, EventArgs e)
{
    listBoxQuestoesSubjetivas.ClearSelected();
}

private void listBoxQuestoesSubjetivas_SelectedIndexChanged(object sender, EventArgs e)
{
    listBoxQuestoesObjetivas.ClearSelected();
}

The problem is that when I click on one, it desiccates both, it’s very strange '-' Remembering that I am using Microsoft.Net Framework 2.0

1 answer

0

Try the following, but logically changing the names of the controls to your.

    private void listBox1_Click(object sender, EventArgs e)
    {
        listBox2.SelectedIndex = -1;
    }

    private void listBox2_Click(object sender, EventArgs e)
    {
        listBox1.SelectedIndex = -1;
    }

That’s how it works too:

    private void listBox1_Click(object sender, EventArgs e)
    {
        listBox2.ClearSelected();
    }

    private void listBox2_Click(object sender, EventArgs e)
    {
        listBox1.ClearSelected();
    }
  • Your first suggestion I’ve tried and gives exactly the same thing, the second suggestion is exactly the same as mine

  • It is not the same, you are using the event "Selectedindexchanged", if you use the event that is in the answer works 100%, note that the answer is with the event "Click". The Selectedindexchanged event clears the selected ones after you have already clicked on the controller, the "Click" event clears the selected ones before Selectedindex is changed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.