Shaitan00 Posted November 15, 2005 Posted November 15, 2005 (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 November 15, 2005 by PlausiblyDamp Quote
Cags Posted November 15, 2005 Posted November 15, 2005 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(); } Quote Anybody looking for a graduate programmer (Midlands, England)?
techmanbd Posted November 15, 2005 Posted November 15, 2005 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 Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Shaitan00 Posted November 15, 2005 Author Posted November 15, 2005 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. Quote
Leaders snarfblam Posted November 16, 2005 Leaders Posted November 16, 2005 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? Quote [sIGPIC]e[/sIGPIC]
Cags Posted November 16, 2005 Posted November 16, 2005 (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 November 16, 2005 by Cags Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.