Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Okay - the way it works is I have 3 radio buttons and one datagrid, each time the user selects one of the radio buttons (because only one can be on at a time) I launch a function (RefreshGUI) that will reload the datagrid given the users new selection.

To determine when a radiobutton has been checked I am using the _CheckedChanged event - sadly this is having some negative effects...

So it goes something like this:

private void rbFINISHED_CheckedChanged(object sender, System.EventArgs e)
{
RefreshGUI();
}

private void rbALL_CheckedChanged(object sender, System.EventArgs e)
{
      RefreshGUI();		
}

private void rbINPROGRESS_CheckedChanged(object sender, System.EventArgs e)
{
      RefreshGUI();		
}

private void RefreshGUI()
{
... RefreshGUI
}

 

So the problem is, when rbFINSIHED is checked and the user goes to check rbALL instead this fires my RefreshGUI() function TWICE, once because rbFINSIHED is unchecking (change) and one because rbALL is being checked (change).

Obviously this greatly inneficient, I need a way so that I only end up firing my RefreshGUI() function ONCE as expected.

Any help/hints would be appreciated, thanks.

Edited by PlausiblyDamp
Posted

I would create a single method similar to the one below and assign it to the CheckedChanged even of all of these checkboxes.

 

private void CheckChanged(object sender, System.EventArgs e)

{

if(((RadioButton)sender).Checked)

RefreshGUI();

}

Anybody looking for a graduate programmer (Midlands, England)?
Posted

the reason it does it twice is because even if it unchecks it is being changed so you get both things happening. Do like Cags suggested. or if you want to keep what you have. throw in an IF statement. I am not that familiar with C# but in VB I just put in the event

 

if RadioButton1.checked then

'code here

end if

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

Cags: GREAT idea - question is how do I call the "CheckChanged" function you wrote? I need it to launch when the user checks one of the boxes... I don't see your "CheckChanged" as an event?

 

techmanbd: That is what I am already doing, RefreshGUI is a set of 3 IF statements, one for each RadioButton - still the function is called twice.

  • Leaders
Posted
techmanbd: That is what I am already doing' date=' RefreshGUI is a set of 3 IF statements, one for each RadioButton - still the function is called twice.[/quote']

RadioB becomes checked, causing RadioA to become unchecked. Now RadioA.CheckChanged is raised, but RadioB is checked, triggering a refresh (since you check all three). Then, RadioB.CheckChanged is raised, and it is checked, triggering a refresh. See?

[sIGPIC]e[/sIGPIC]
Posted (edited)

Simply use the Event browser from the visual studio IDE and select that method, or add the following line to the constructor.

 

this.radioButton1.CheckedChanged += new System.EventHandler(this.CheckChanged);

 

NOTE: - Obviously you'll need to do the equivalent of that line for all radiobuttons, but using the event browser is a far easier option.

Edited by Cags
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...