How do I make a label visible/invisible depending on the value of a boolean field in a form customization?

Hello,

I am trying to make a label with information needed visible/invisible depending on the boolean value of a UD field I created. The form has access to the value which I checked by putting a checkbox tied to it on the screen as a test.

Any help is appreciated. I can supply more information if this seems vague.

Thanks,

Shawn

Is this an SSRS report?

edit: You probably mean label, as in just text on a screen.

You need a change event on the check box.

Use the wizard to make that.

Then and if statement for true or false and then there are propertied on the label.

Something like this.
LabelName.Visible = false;

I am doing it on the Service Call Center screen, Lines Tab. They want a box to appear if a box is checked on the Customer form and be hidden if the box is not checked.

Yes, trying to do the info with just a label instead of a textbox.

See edits above.

Not sure which wizard to use. Don’t do too much with them right now, lol.
The checkbox does not show on this screen. Do I create one and set to hidden to trigger it?

I was thinking it was for user input it would show/not show. My misunderstanding.

So you want this on form load. Again with the wizard. And then the same if statement to show that being visible or not.

I would recommend clicking through all of the things in the wizard that you can do. There is a lot of stuff that will make you a lot faster at this stuff instead of trying to write it from scratch.

And no, your check box should need to be on the screen, you should be able to see it in the dataview whether it’s bound to a control or not.

I hate to ask but how would you write the if statement to access the field?

To get the value, I had to create a FKV called Customer. The field is called: Instrument_Returned_c

One day, I will be able to tie all of this together on my own but for now, any help is truly appreciated.

If you go to tools->obsject explorer, you can look through all of the dataviews that are loaded up in the customization. Your FKV should show up in there, and you should see how you can get to those properties.

When I go to that screen you show, I only get the VB version. I tried to hack together what it showed with what you show and came up with this.

<code>
private void ServiceCallCenterEntryForm_Load(object sender, EventArgs args){
		EpiDataView customerView = (EpiDataView)(oTrans.EpiDataViews["Customer"]);
		Boolean instrumentReturned = (Boolean)(customerView.dataView[customerView.Row]["Instrument_Returned_c"]);

		// Add Event Handler Code
		if(instrumentReturned == true){
			lblInstrumentReturned.Visible = true;
		}else{
			lblInstrumentReturned.Visible = false;
		}
	}
</code>

It compiles fine but does not work. I now also get an error when I open Service Call Center.
OnCustomCodeFormLoad
Exception has been thrown by the target of an invocation
Any ideas where I strayed? I don’t know C# much at all.

Ah, my mistake (again)

form load won’t have any data in it yet. Move that to an EpiViewNotification.

Can you access the label directly like that without grabbing a Native Reference (GUID)?

That’s seems super odd. Can you show me a screen shot of that?

If you use the name in the properties you can do that. I do it all the time.

I am on 10.1.500.23 if that makes a difference.

Hmmm… didn’t know that
I’ve always used a Native Reference (GUID) … just because I learned that a long time ago.
e.g.
EpiLabel myLabel = (EpiLabel)csm.GetNativeControlReference(“xxxxx-xxxxx-xxxxx-xxxxx-xxxxxx”);
mylabel.Visible = false;

Something else to “un” learn I guess.

2 Likes

To be clear, I still use that for native controls, mostly because their names end up being super confusing, but in essence I think it’s mostly a way to just rename it in your code. Maybe someone has a better reason as to why you need to do this?

edit: I would have to test to be sure, but I don’t know if you can use the name on native controls. But it works fine for custom controls.

I had to get rid of the outer if statement but used the row > -1 to hold my if statement. Worked like a charm after that! Thanks to @Banderson!!!

You don’t want to do that. Change AddRow to Initialize, and it should work.

Otherwise, you will be pounding that event way more than you need to.

I made the change and it still works. Thanks again!!

1 Like