How do I change the radiobutton when listbox selection has changed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 3 radio buttons for include, exclued or 'select all' from the listbox
items. If a user selects the 'Select All' button' then all items in listbox
is hi-lited as selected. Now, when user selects one item out of the 'all
selected' listing then there is now only one item selected. How and where
can I put in some code to change the selected radio button to the 'include'
since it is no longer in select all mode.

Thanks,
Alpha
 
Yes, I tried that alreday. It's not working properly because I also have
code for when that radio button status changed. It's interferring with the
listbox selectedindeschange. It took care of de-selecting the 'Include all'
radio button and select the Include all button. But the new problem with
this code is now when I select the 'Select All' radio button it will flash
the radio button was check in the blink of an eye and then uncheck it and
check the 'Incldue' radio button even when the entire list is selected. Is
there anyway around this?

Thanks,
Alpha

if (radioAllItems.Checked == true)
{
// for (int x = 0; x < this.lstSelections.Items.Count; x++)
// {
// this.lstSelections.SetSelected(x, true);
// }

this.Show();

// Do focused work here.

if (this.listBox1.Items.Count > 0)
{
this.listBox1.Focus();
this.listBox1.SetSelected(0, true);
SendKeys.Send("+{END}");
}

}
else
lstSelections.ClearSelected();
}

private void lstSelections_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (radioAllItems.Checked == true)
if (this.lstSelections.SelectedItems.Count < lstSelections.Items.Count)
{
radioAllItems.Checked = false;
radioInclude.Checked = true;
}

}
 
You could create a flag to indicate the listbox is changing and not do your
code for the radio button when it is changing. See below.

bool listBoxChanging

in your Select Index Change
listBoxChanging = true;
do your code here
listBoxChanging = false;

In the Radio button index change
if !listBoxChanging
{
existing code
}

--
Thanks
Wayne Sepega
Jacksonville, Fl


"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
Nop, it's not working. I'm setting the same button in both event and it's
conflicting with each other. You'll see that if you look at my code posted
previously. I tried setting flags in both events (codes below) and it still
doesn't work right. I wonder how does people handel issue like this. Well,
I give up. I'm going to remove the 'select all' button option. Thank you
for your help anyway.

Alpha
 
Back
Top