Button to check CheckBox

I’m trying to do where the end user clicks a button and it selects the checkbox as true only. (Note: Higher ups want a button and not another checkbox.) How would this be done? I have the button on the appropriate form, but I can’t figure out how to get it work the way I need it to.

We’ll need a little more information about what you’ve done so far. When you say that you have the button, did you wire up the method to make the button click do something yet?.

Do you know how to get to using MessageBox.Show("I clicked my button"); and make sure the button has an event?

1 Like

Inside the onclick event of your button, put some code like this:

if (YourCheckBox.Checked = false)
{
YourCheckBox.Checked = true;
}
1 Like

Here’s screenshots of what I have done so far:


1 Like

Yup that’s the way to get the button to click. Please (for the love of God) rename the button first though.

Then when you have that, get ahold of the dataview and you’ll adjust the value there.

2 Likes

In the customization tools, there is the object explorer. That will show you how to get to the dataviews, then you can change the value of the object.

If I were you, I would spin up a UD field that you can name intelligently, unless the field is already in use. While it’s more of a pain for present you, future you will thank you for that.

See if you can figure out the object explorer, and if you get stuff post your questions.

2 Likes

I didn’t pay attention to the binding. Binding the button to a check box won’t do anything except for make the button read only if the field is read only. (for example if the record isn’t loaded yet). So that’s helpful, but it doesn’t actually add any functionality for you.

So you’ll have to code what you want the button to do on the button click.

1 Like

I tend to handle these kind of things via BPM. If field == true, ignore or throw error if user tries to make it false.

At the form level, I might also set the field to read only if true so they can’t even click the thing.

I want them to be able to press the button to make it true. I will use a BPM to do the what is needed, and at the end, change it back to false. But, the boss wants a button, so…

So, I found the dat views, and found the checkbox I was looking for. I’m assuming this is where I put the code to check it upon the click?

Note: I just picked this checkbox to use, the final one will be a new checkbox properly named.

Correct. in the Method epiButton_Click(), you set the dataview field to true.

I must be missing something.

C’mon @Will79 … That’s not a question. What are you thinking?

(You gotta think a little here, I’m not going to spoon feed you) :wink:

I do not see a method listed here. Do I add it in? Or am I in the wrong place?

You already have the method. That was in your wizard that you showed earlier. This is how you get ahold of the data view. (that’s the first line). And the second line is how you would get what the field is.

In your case since you are trying to set it, you flip that.

EpiDataView WillsAwesomeDV = (EpidataView)(oTrans.EpidataViews["OrderHed"]);
WillsAwesomeDV.dataView[[WillsAwesomeDV].Row["Checkbox14"] = true;

So you assign the dataview to whatever you want to call it. Then in the dataview you set the value.

This goes in the method that was created with the wizard from the screen shot you posted.

See if that compiles.

Edit: it goes here. (In the script editor tab)

1 Like

Ok, that makes sense now. I’ll keep this as a template for other things I try to do. Thank you!

As for the compile, well it errored out.

Compiling Custom Code …

----------errors and warnings------------

Error: CS1525 - line 73 (432) - Invalid expression term ‘[’
Error: CS1003 - line 73 (432) - Syntax error, ‘]’ expected
Error: CS1002 - line 73 (432) - ; expected
Error: CS1525 - line 73 (432) - Invalid expression term ‘]’

** Compile Failed. **
I noticed you had an extra [ in there, so I removed it and it gave me these for errors:
Error: CS0246 - line 72 (431) - The type or namespace name ‘EpidataView’ could not be found (are you missing a using directive or an assembly reference?)
Error: CS1061 - line 72 (431) - ‘Erp.UI.App.SalesOrderEntry.Transaction’ does not contain a definition for ‘EpidataViews’ and no extension method ‘EpidataViews’ accepting a first argument of type ‘Erp.UI.App.SalesOrderEntry.Transaction’ could be found (are you missing a using directive or an assembly reference?)
Error: CS1502 - line 73 (432) - The best overloaded method match for ‘System.Data.DataView.this[int]’ has some invalid arguments
Error: CS1503 - line 73 (432) - Argument 1: cannot convert from ‘Ice.Lib.Framework.EpiDataView’ to ‘int’

Actually, I am using one that is already being used. Let me create fresh one in test and try it again.

Sorry, extra []

Take those out

EpiDataView WillsAwesomeDV = (EpidataView)(oTrans.EpidataViews["OrderHed"]);
WillsAwesomeDV.dataView.[WillsAwesomeDV.Row]["Checkbox14"] = true;

I adjusted and now down to one error! :rofl:

----------errors and warnings------------

Error: CS1001 - line 73 (432) - Identifier expected

** Compile Failed. **

Can you take a screenshot for me? That looks correct from what I can tell.