Search code examples
c#vb.netactivereports

Hiding a single control on a Details Section in ActiveReports


I'll try to simplify the situations as much as possible.

I have an ActiveReports subreport that has a control which I fill using FetchData event. Sometimes I need to hide the control if its blank or in this occassion the value is Cotton but Polyester should appear. The problem is that when I hide a control, it hides the control on every occurrence in the report not just one instance that so need. Is there something I'm doing wrong.

I define the control in InitializeReport

Material1 = DirectCast(Detail.Controls("Material1"), Label)
Material2 = DirectCast(Detail.Controls("Material2"), Label)

I set up the Datafield for the control in the DataInitialize event

Fields.Add("Material1")
Fields.Add("Material2")

In the FetchData event, I fill the control, so three records, the control gets populated appropriately. There's nothing wrong. If the second record has a value then thats fine. e.g.

1st Record, first call of the FetchData event.

Fields("Material1").Value = "Polyester" 
Material1.Value = "Polyester"
Fields("Material2").value = "Wool"
Material2.Value = "Wool"

2nd Record, second call of the FetchData event.

Fields("Material1").Value = "Cotton"
Material1.Value = "Cotton"
Fields("Material2").Value = "Wool"
Material2.Value = "Wool"

If I want to hide the second record/control from being seen, after the control is filled, I hide the control in the Details_Format event, however, it hides all three Material controls rather than just the one individual instance. What could I be doing wrong?

If Fields("Material1").value = "Cotton" then 
    Material1.Visible = false 
End if 

I want wool to appear twice, in both records but Cotton to not appear in the second grouping. I just can't hide the Cotton controls. I don't want to simply blank out the Material1 because I need to hide the control so that I can move controls up and reorganise the report. There is a label beside Material1 which I hide as well as the Material1.

VB or C# solution please.


Solution

  • You need to add Else to you If or replace with

    Material1.Visible = Not (Fields("Material1").Value = "Cotton")
    

    that way it turns on or off based on the value. When you set the property you're setting it on the instance for the whole control, the subreport has only one instance not one for each detail.

    hope this helps.