Untick a checkbox based on ticking another checkbox

Good Morning! I’m looking to ensure that a user can only check one checkbox. Both can never be checked. Id like one of the boxes to untick based on if the user ticks the other checkbox. A user can untick the same checkbox so none are ticked. This is what I have so far. And here is a gif of what is happening. I need to click the box a 2nd time for it to check. But it does clear the other box fine.

 epiCheckBoxIsGold.CheckedChanged += (o, e) =>
            {
                if ((o as EpiCheckBox).Checked == true)
                {
                    epiShapeIsGold.Enabled = true;
                    epiShapeIsGold.Status = (Ice.Lib.Framework.StatusTypes) 4;
                    epiShapeIsGold.BackColor = System.Drawing.Color.Gold;
                    epiShapeIsGold.Appearance.BackColor2 = System.Drawing.Color.Gold;
                    epiCheckBoxIsPlatinum.Checked = false;
                }
                else
                {
                    epiShapeIsGold.Enabled = false;
                }
            };

            epiCheckBoxIsPlatinum.CheckedChanged += (o, e) =>
            {
                if ((o as EpiCheckBox).Checked == true)
                {
                    epiShapeIsPlatinum.Enabled = true;
                    epiShapeIsPlatinum.Status = (Ice.Lib.Framework.StatusTypes) 4;
                    epiShapeIsPlatinum.BackColor = System.Drawing.Color.PowderBlue;
                    epiShapeIsPlatinum.Appearance.BackColor2 = System.Drawing.Color.PowderBlue;

                    epiCheckBoxIsGold.Checked = false;
                }
                else
                {
                    epiShapeIsPlatinum.Enabled = false;
                }
            };

checkbox%20tick

Use EpiCombox or EpiRadioButton?

2 Likes

Thanks!
I can do that too, I’m just curious if anyone has been successful with doing this on check boxes.

Hmm well I did something like this but within an UltraGrid to make it so only one checkbox be allowed to be checked at a time. Obviously this doesn’t answer your question, but perhaps it might spur something.

Perhaps you could think of a way to tie the checked state of each of those check boxes to a structure, i.e. a list or something and flip the value of the opposing check box

private void grdSigners_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
	{
		//Allows for only 1 row to be selected as "Primary"
		foreach(var item in grdSigners.Rows)
		{
			if(args.Cell.Row.Index != item.Index)
			{
				item.Cells["Primary"].Value = false;
				item.CancelUpdate();
			}
		}
	}

I think what’s happening is that the CheckedChanged event is firing again when you change the checked value via the code. Since the event handler only considers the value of the checkbox it’s assigned to, it blindly sets the values.

You need to know what the values of both checkboxes are at the time to evaluate what should happen. Here’s a super-simple example I put together using two checkboxes and the wizard generated events for CheckedChanged.

private void epiCheckBoxC1_CheckedChanged(object sender, System.EventArgs args)
{
	if (epiCheckBoxC1.Checked && epiCheckBoxC2.Checked)
	{
		epiCheckBoxC2.Checked = false;
	}
}

private void epiCheckBoxC2_CheckedChanged(object sender, System.EventArgs args)
{
	if (epiCheckBoxC2.Checked && epiCheckBoxC1.Checked)
	{
		epiCheckBoxC1.Checked = false;
	}
}

checkboxes

4 Likes

That is awesome! Just what I needed. Thanks!

And thank you to everyone else for your input! I know I could have used a pick list as well but just wanted to see if this was possible.

Regardless of either of the methods posted above…once the controls are bound to a data field that issue occurs :frowning:

And I cannot use a radio control as there needs to be the option that both are unchecked. Radio controls are only supposed to be used in the event 1 thing needs to be selected. I need to have the “default” option of silver. So gold or platinum need to be selected if need be. Therefore silver is not a selectable option as it is the base default.

@josecgomez helped me with a checkbox issue a while back. Not exactly the same but a different approach to checking checkboxes :slight_smile:

I’m not sure I follow what “that” issue is when you talk about data binding.

What’s the issue with using 3 radio buttons? I’m assuming you are trying to control one field correct? If silver needs to be null, I think you can make that a value of a radio button. Then a clever arrangement on the UI can make the default choice clear. You could also make a button to clear the value. They would both be empty then.

If you are dealing with more than one field, and you are having trouble when you data binding, you could probably do the setting yourself. You would set the correct state of the check boxes on load, then when you check the boxes, set the value(s?) in the data view within the code blocks shown above. I’m not sure what problem you are having, but maybe adding a layer of separation would help?

Hey guys,

i know this is an older topic but I was trying to accomplish the same thing. @jstephens code worked well but it did still uncheck both boxes. So I just added an extra line to call out selecting one of the boxes as ‘true’.

Works perfect, binding and all.

Thought I would post it on here in case anyone else is ever in search of the same thing.

> 

private void C_S2_EngDisYes_CheckedChanged(object sender, System.EventArgs args)
	{
		if (C_S2_EngDisYes.Checked && C_S2_EngDisNo.Checked)
		{
			C_S2_EngDisNo.Checked = false;
			C_S2_EngDisYes.Checked = true;
		}
	}

	private void C_S2_EngDisNo_CheckedChanged(object sender, System.EventArgs args)
	{
		if (C_S2_EngDisNo.Checked && C_S2_EngDisYes.Checked)
		{
			C_S2_EngDisYes.Checked = false;
			C_S2_EngDisNo.Checked = true;
		}
	}

>
2 Likes

Jason,
I am trying your code in Script Editor, but I get 'the name ‘chkVP’ does not exit in the current context . I am stuck at adding the existing Epicor checkbox (chkVP) to this customization. Any insight you or others could provide would be greatly appreciated.
David

The code from above uses custom objects (because I was just doing a lazy proof-of-concept) so they’re set up within the custom code layer and can be easily accessed by name. Native controls set themselves up in the base form and so aren’t as easily accessible.

You’ll want to make your own reference with something like this:

Ice.Lib.Framework.EpiCheckBox chkVP = (Ice.Lib.Framework.EpiCheckBox)this.csm.GetNativeControlReference("GUID");

where GUID is the EpiGuid from the control’s properties. You can do this first thing within the Checked Changed event method or as a global variable at the beginning of the Script class (not recommended).

Alternately, if you only care about if it’s checked, you could reference it directly in the conditional statement or assign its state to a new, temporary variable.

bool c1 = ((Ice.Lib.Framework.EpiCheckBox)this.csm.GetNativeControlReference("GUID")).Checked;

Heady stuff.

Basically I am trying to setup in Customer Maintenance that when the UD field Inactive_c is checked, it will uncheck Valid Payer, Valid SoldTo and ValidShipTo, rendering the Customer inert for the most part. I liked your earlier example, and hope to get it working in this instance.

Thank you

Don’t set the controls directly. Instead, you should set the data view.

Here’s a onClick event for a button, which you could easily adapt to the event handler on your UD chckbox

private void btnDeactivate_Click(object sender, System.EventArgs args)
	{
	// ** Place Event Handling Code Here **
	EpiDataView edv = (EpiDataView)(oTrans.EpiDataViews["Customer"]);

	edv.dataView[edv.Row]["ValidPayer"] = false;
	edv.dataView[edv.Row]["ValidSoldTo"] = false;
	edv.dataView[edv.Row]["ValidShipTo"] = false;
	edv.dataView[edv.Row]["AllowOTS"] = false;
	edv.dataView[edv.Row]["AllowShipTo3"] = false;	
	/* etc ...*/ 
	}

just add a check to see if your checkbox was changed to TRUE.