I am using two radiobuttons in visual studio window form. Now I want some buttons to be factional when radiobutton1 is pressed and the same thing with radiobutton2.
To do so, I copied and paste the coding of the buttons in the radiobutton1 loop, as show below:
....Now I want some buttons to be factional when radiobutton1 is pressed and the same thing with radiobutton2. .
what is "factional"? Also, what type of errors are you seeing? We can't help if you only say you're getting an error - you need to be specific on what isn't working and the actual error you're getting.
You cannot have a procedure inside another procedure. Meaning, you cannot contain void button1_Click inside radioButton1_CheckedChanged . You would have to use some sore of boolean logic to determine which radio button was selected or not.
I used boolean but it will not look neat when having lets say 10 buttons for each radiobutton. This is because you need to add "(if bool == true)" for every button as shown below:
I used boolean but it will not look neat when having lets say 10 buttons for each radiobutton. This is because you need to add "(if bool == true)" for every button as shown below:
isn't valid code syntax. Perhaps this is a typo in your post, but if it isn't you might want review C# syntax basics. Also, try to be clearer on what you are actually trying to do. I'm guessing that you want to enable/disable some buttons based which radio button is selected, but I'm not sure from your description.
At any rate, check out the following post for a couple of different approaches toward this end.
isn't valid code syntax. Perhaps this is a typo in your post, but if it isn't you might want review C# syntax basics.
Yes that's a typo.
Code:
Also, try to be clearer on what you are actually trying to do. I'm guessing that you want to enable/disable some buttons based which radio button is selected, but I'm not sure from your description.
That's what I was trying to do. I solved the problem by using 'button.Enabled = false;' as shown below:
That's one approach but it doesn't scale well. Consider what would happen if you had two groups of 5 radio buttons managing the enable/disable state of 10 buttons each?
Check out the two sample code projects in the link I posted and try to understand those approaches. Both eliminate the need to create check changed handlers for every radio button which should result in smaller, more maintainabile code.
Bookmarks