I am trying to get the seleted radioButton from a group of radio buttons.
The program is supposed to check on the search form for controls that match the selected radiobuttons. The radiobuttons are named AND and OR
For example

Field 1 :Customer No Search String: 123353

   ANDradioButton          ORradiobutton

Field 2 : LastName Search String2 : Cruz

If a person selects AND radio, the program must load the data put in the search text into a gridView like this::

Customer No: 123353
LastName: Cruz

If a person selects OR radio button, the program must load the data put in the search text into a gridView like this::

either of them will be viewed: can be the Customer No or the LastName..

Any suggestions on how i can go about doing this will be appreciated.

I should use checkboxes here.
That way you can select the options you want.
Radiobutton are for mutabily exclusive selections.

Use a panel. Put a Panel (or GroupBox) on your form. Put the radio buttons on the panel (or GroupBox). Then use the "CheckChanged" (radio button) event:

AndRadioButton_CheckedChanged

        private void AndRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (AndRadioButton.Checked)
            {
                Console.WriteLine("AndRadioButton selected.");
            }//if
            else
            {
                Console.WriteLine("AndRadioButton NOT selected.");
            }//else

        }

OrRadioButtion_CheckedChanged

        private void OrRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (OrRadioButton.Checked)
            {
                Console.WriteLine("OrRadioButton selected.");
            }//if
            else
            {
                Console.WriteLine("OrRadioButton NOT selected.");
            }//else

        }

Since the radio buttons are part of a group (by using a Panel or GroupBox), when one is checked the other will be unchecked. So we only need to worry about in the beginning if both are unchecked. To deal with that situation, use an event for each radio button and remove the "else" statements that I put in the code above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.