473,785 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a limit on # of radio buttons

I have 8 radio buttons on my Windows form but I can only select up to the
first 4. If I click on any button beyond the 4th one and then come back into
the program again the 4th button is always checked instead of the 5th or 6th
etc. I followed the logic thru the debugger and can see where the 5th button
is progammatically checked but the window shows the 4th checked instead.
Does anyone have a clue as to what's going on here? All of the radio buttons
are in a group box.
Dave
Jul 17 '08 #1
10 2209
Parrot wrote:
I have 8 radio buttons on my Windows form but I can only select up to the
first 4. If I click on any button beyond the 4th one and then come back into
the program again the 4th button is always checked instead of the 5th or 6th
etc. I followed the logic thru the debugger and can see where the 5th button
is progammatically checked but the window shows the 4th checked instead.
Does anyone have a clue as to what's going on here? All of the radio buttons
are in a group box.
Dave
If there is a limit, it's certainly not four. Rather something like
65536 or 4294967296.

Where are you storing the data? Have you checked if the stored value is
correct or not?

How do you make the right radio button selected when you load the data?

--
Göran Andersson
_____
http://www.guffa.com
Jul 17 '08 #2
The logic I am using is very simple. When loading the program I check a
passed variable. The code goes like this:

if(dateformat.C ompare("month") ==0)
{
radioButton5.Ch ecked = true;
}

However, when the window is displayed, it shows radioButton4 checked
instead. I followed the logic in debug mode and that is the only radiobutton
programmaticall y checked. I don't understand how something so simple cannot
work.
Dave

"Göran Andersson" wrote:
Parrot wrote:
I have 8 radio buttons on my Windows form but I can only select up to the
first 4. If I click on any button beyond the 4th one and then come back into
the program again the 4th button is always checked instead of the 5th or 6th
etc. I followed the logic thru the debugger and can see where the 5th button
is progammatically checked but the window shows the 4th checked instead.
Does anyone have a clue as to what's going on here? All of the radio buttons
are in a group box.
Dave

If there is a limit, it's certainly not four. Rather something like
65536 or 4294967296.

Where are you storing the data? Have you checked if the stored value is
correct or not?

How do you make the right radio button selected when you load the data?

--
Göran Andersson
_____
http://www.guffa.com
Jul 17 '08 #3
"Parrot" <Pa****@discuss ions.microsoft. comwrote in message
news:AA******** *************** ***********@mic rosoft.com...
>
However, when the window is displayed, it shows radioButton4 checked
instead. I followed the logic in debug mode and that is the only
radiobutton
programmaticall y checked. I don't understand how something so simple
cannot
work.
Dave
VB6 dev here, so dotNet Radio buttons may've changed (but I doubt it, since
they were the same in VB3/NT3.51 as they are in VB6/XP).. They're not as
easy to work with as they seem.

Since they change to "True" when they get focus, no matter what, you have to
make sure of a few things before hiding/showing/disabling/enabling them. The
simplest method I've seen (and used extensively) is to disable their
container until focus is where you'd like it to be.

For example... if Button3's currently = True, but when your form shows (or
you're enabling/disabling controls), the first control that gains focus is
Button5, Button5 will be set = True, no matter what. So, disabling the
container forces focus elsewhere, which prevents this problem... since my
apps control hardware and are used in the cleanroom, we don't allow focus to
"stick" to a control that may cause something to move... too many people can
walk up and lean on the keyboard, etc.... so, I usually drop a picturebox on
the form, set its background = form's background and set focus to that.
Since the picturebox doesn't show a focus rectangle, and there's no code in
its click event, people can lean on the keyboard all they want without
worry.

In your case, maybe you have a textbox or command button to set focus to,
instead.... what ever the case, you'll probably find your "rouge radio
button" that keeps setting itself = true is getting focus without your
involvement..

Jul 17 '08 #4
This is really crazy. The only way I can keep radiobutton4 from being
checked even though radiobutton5 is checked is to disable radiobutton4.
However, then if radiobutton6 is checked then the check mark goes to
radiobutton5, the one above it. If I disable radiobutton5 when checking
radiobutton6 the check mark will go back to radiobutton4. I removed and
re-added the radiobuttons but to no avail. I still get the same problem.
Simply put. the system will not properly handle beyond 3 radio buttons in the
same group. Such a simple program and I am spinning my wheels. It couldn't
be a bug could it?
Dave

"Ken Halter" wrote:
"Parrot" <Pa****@discuss ions.microsoft. comwrote in message
news:AA******** *************** ***********@mic rosoft.com...

However, when the window is displayed, it shows radioButton4 checked
instead. I followed the logic in debug mode and that is the only
radiobutton
programmaticall y checked. I don't understand how something so simple
cannot
work.
Dave

VB6 dev here, so dotNet Radio buttons may've changed (but I doubt it, since
they were the same in VB3/NT3.51 as they are in VB6/XP).. They're not as
easy to work with as they seem.

Since they change to "True" when they get focus, no matter what, you have to
make sure of a few things before hiding/showing/disabling/enabling them. The
simplest method I've seen (and used extensively) is to disable their
container until focus is where you'd like it to be.

For example... if Button3's currently = True, but when your form shows (or
you're enabling/disabling controls), the first control that gains focus is
Button5, Button5 will be set = True, no matter what. So, disabling the
container forces focus elsewhere, which prevents this problem... since my
apps control hardware and are used in the cleanroom, we don't allow focus to
"stick" to a control that may cause something to move... too many people can
walk up and lean on the keyboard, etc.... so, I usually drop a picturebox on
the form, set its background = form's background and set focus to that.
Since the picturebox doesn't show a focus rectangle, and there's no code in
its click event, people can lean on the keyboard all they want without
worry.

In your case, maybe you have a textbox or command button to set focus to,
instead.... what ever the case, you'll probably find your "rouge radio
button" that keeps setting itself = true is getting focus without your
involvement..

Jul 18 '08 #5
On Thu, 17 Jul 2008 18:26:02 -0700, Parrot
<Pa****@discuss ions.microsoft. comwrote:
[...]
Simply put. the system will not properly handle beyond 3 radio buttons
in the
same group. Such a simple program and I am spinning my wheels. It
couldn't
be a bug could it?
Surely it's a bug. But it's probably in your code.

Unfortunately, you haven't shared that with us. So it's not possible for
us to point it out.

If you can post a concise-but-complete code sample that reliably
reproduces the problem, it should be possible to provide a more complete
answer.

Pete
Jul 18 '08 #6
I am pasting the entire code for the C# program below. As I mentioned
earlier I can follow the logic in debug mode and I can see where radiobutton5
is set to checked but it still shows radiobutton4 with the check when the
window is displayed.

namespace WindowsApplicat ion1
{
public partial class convertdate : Form
{

public string xdateformat;

public convertdate(str ing field, string dateformat)
{
InitializeCompo nent();
label2.Text = field;

xdateformat = dateformat;

if (dateformat.Com pareTo("1") == 0)
radioButton1.Ch ecked = true;
else
if (dateformat.Com pareTo("101") == 0)
{
radioButton2.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("107") == 0)
{
radioButton3.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("year") == 0)
{
radioButton4.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("month") == 0)
{
radioButton5.Ch ecked = true;
radioButton1.Ch ecked = false;

}
else
if (dateformat.Com pareTo("day") == 0)
{
radioButton6.Ch ecked = true;
radioButton1.Ch ecked = false;

}
else
if (dateformat.Com pareTo("monthna me") == 0)
{
radioButton7.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("dayname ") == 0)
{
radioButton8.Ch ecked = true;
radioButton1.Ch ecked = false;
}

}

private void OnCancel(object sender, EventArgs e)
{
this.Close();
}

private void OnOk(object sender, EventArgs e)
{
if (radioButton1.C hecked)
xdateformat = "1";
else
if (radioButton2.C hecked)
xdateformat = "101";
else
if (radioButton3.C hecked)
xdateformat = "107";
else
if (radioButton4.C hecked)
xdateformat = "year";
else
if (radioButton5.C hecked)
xdateformat = "month";
else
if (radioButton6.C hecked)
xdateformat = "day";
else
if (radioButton7.C hecked)
xdateformat = "monthname" ;
else
if (radioButton8.C hecked)
xdateformat = "dayname";
this.Close();
}
}
}

"Peter Duniho" wrote:
On Thu, 17 Jul 2008 18:26:02 -0700, Parrot
<Pa****@discuss ions.microsoft. comwrote:
[...]
Simply put. the system will not properly handle beyond 3 radio buttons
in the
same group. Such a simple program and I am spinning my wheels. It
couldn't
be a bug could it?

Surely it's a bug. But it's probably in your code.

Unfortunately, you haven't shared that with us. So it's not possible for
us to point it out.

If you can post a concise-but-complete code sample that reliably
reproduces the problem, it should be possible to provide a more complete
answer.

Pete
Jul 18 '08 #7
On Thu, 17 Jul 2008 20:58:02 -0700, Parrot
<Pa****@discuss ions.microsoft. comwrote:
I am pasting the entire code for the C# program below.
That wasn't a complete code sample.

Also, as a minor suggestion for making your code more pleasant for others
to read: when writing "if/else if/else" statements, it's customary to
avoid excessive indentation by writing "else if" on the same line, and
indenting each "else if" and the final "else" the same amount as the
initial "if".

Pete
Jul 18 '08 #8
"Parrot" <Pa****@discuss ions.microsoft. comwrote in message
news:26******** *************** ***********@mic rosoft.com...
>I am pasting the entire code for the C# program below. As I mentioned
earlier I can follow the logic in debug mode and I can see where
radiobutton5
is set to checked but it still shows radiobutton4 with the check when the
window is displayed.

namespace WindowsApplicat ion1
{
public partial class convertdate : Form
{

public string xdateformat;

public convertdate(str ing field, string dateformat)
{
InitializeCompo nent();
label2.Text = field;

xdateformat = dateformat;

if (dateformat.Com pareTo("1") == 0)
radioButton1.Ch ecked = true;
else
if (dateformat.Com pareTo("101") == 0)
{
radioButton2.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("107") == 0)
{
radioButton3.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("year") == 0)
{
radioButton4.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("month") == 0)
{
radioButton5.Ch ecked = true;
radioButton1.Ch ecked = false;

}
else
if (dateformat.Com pareTo("day") == 0)
{
radioButton6.Ch ecked = true;
radioButton1.Ch ecked = false;

}
else
if (dateformat.Com pareTo("monthna me") == 0)
{
radioButton7.Ch ecked = true;
radioButton1.Ch ecked = false;
}
else
if (dateformat.Com pareTo("dayname ") ==
0)
{
radioButton8.Ch ecked = true;
radioButton1.Ch ecked = false;
}

}

private void OnCancel(object sender, EventArgs e)
{
this.Close();
}

private void OnOk(object sender, EventArgs e)
{
if (radioButton1.C hecked)
xdateformat = "1";
else
if (radioButton2.C hecked)
xdateformat = "101";
else
if (radioButton3.C hecked)
xdateformat = "107";
else
if (radioButton4.C hecked)
xdateformat = "year";
else
if (radioButton5.C hecked)
xdateformat = "month";
else
if (radioButton6.C hecked)
xdateformat = "day";
else
if (radioButton7.C hecked)
xdateformat = "monthname" ;
else
if (radioButton8.C hecked)
xdateformat = "dayname";
this.Close();
}
}
}

"Peter Duniho" wrote:
>On Thu, 17 Jul 2008 18:26:02 -0700, Parrot
<Pa****@discus sions.microsoft .comwrote:
[...]
Simply put. the system will not properly handle beyond 3 radio buttons
in the
same group. Such a simple program and I am spinning my wheels. It
couldn't
be a bug could it?

Surely it's a bug. But it's probably in your code.

Unfortunatel y, you haven't shared that with us. So it's not possible for
us to point it out.

If you can post a concise-but-complete code sample that reliably
reproduces the problem, it should be possible to provide a more complete
answer.

Pete
We need the code behind the form. That's where the grouping of radio
buttons is controlled. You have a grouping error.

Mike.
Jul 18 '08 #9
On Jul 17, 9:58*pm, Parrot <Par...@discuss ions.microsoft. comwrote:
I am pasting the entire code for the C# program below. *As I mentioned
earlier I can follow the logic in debug mode and I can see where radiobutton5
is set to checked but it still shows radiobutton4 with the check *when the
window is displayed.
There's nothing wrong with your code, specifically, I pasted it into
an application
and it worked fine. The problem is probably in what you do with the
xdateformat
variable after the form closes. Can you show the code that calls this
form?

matt
Jul 18 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6163
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know how to add radio buttons and checkboxes using the existing code mentioned on the url? Thank you!
2
3155
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have two radio buttons to indicate sex (M F). When you have multiple text input boxes with the same...
6
3293
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked The problem i am facing is that i do not know how many yes/no radio groups will be generated
2
5431
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and I want to be able to retrieve the selected value from each of the sets of radio buttons.The names of each group of radio buttons is set by the database and I don't know how to retrieve the values because I don't know the names of these radio...
2
11982
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at run time but with fixed radio buttons (like from an array). I need to create radio buttons based...
1
6891
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
10
6104
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
2
5893
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on the form by changing the visible state of the radio buttons and labels utilising back and next buttons. E.g. Next button makes current radio buttons and labels invisible and
4
2520
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see all twelve. User2 would see buttons 1-3,10-12 and NOT any others, and so on. Since there are several buttons on the page (each one would run a report for them), is there a way to - in an onclick event for each of the buttons - to...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.