How to add variable category from code

Stimulsoft Reports.WEB discussion
Post Reply
JockeD
Posts: 77
Joined: Fri Apr 17, 2009 1:47 pm
Location: Sweden

How to add variable category from code

Post by JockeD »

Hello,

I create a number of variables from code and it works well.
I would also like to add categorys to put my variables in but I don't know how to do that from code.

I suspect that i missing something obvious here but i can't figure what it is.


Regards Joakim
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How to add variable category from code

Post by Edward »

Hi Joakim,

Please create a category first:

Code: Select all

report.Dictionary.Variables.Add("MyCategory");
report.Dictionary.Variables.Add(new Stimulsoft.Report.Dictionary.StiVariable("MyCategory","MyVariable", "MyAlias",typeof(int),"10",false));
And we have added the option of registering of the new category for variable automatically into our to-do list.

Thank you.
JockeD
Posts: 77
Joined: Fri Apr 17, 2009 1:47 pm
Location: Sweden

How to add variable category from code

Post by JockeD »

Thank you,

I can't belive I missed that.

On follow up question.

How can I check if a category already exists?
With a 'normal' variable I can just create a new variable and if it exists it will be replaced, but if i do the same with a category i will have two categorys with the same name.

I have tried...

Code: Select all

Report.Dictionary.Variables.Add("myCategory")
If Not Report.Dictionary.Variables.Contains("myCategory") Then
    Report.Dictionary.Variables.Add("myCategory")
End If
This still adds two categorys.

Regards Joakim


Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How to add variable category from code

Post by Edward »

Hi Joakim,

In that case you need add the following code:

Code: Select all

    Dim addTheCategory As Boolean = True
    Dim variable As StiVariable
    For Each variable In report.Dictionary.Variables
        If (variable.Category = "MyCategory") Then
            addTheCategory = False
            Exit For
        End If
    Next
    If addTheCategory Then
        report.Dictionary.Variables.Add("MyCategory")
    End If
Thank you.
JockeD
Posts: 77
Joined: Fri Apr 17, 2009 1:47 pm
Location: Sweden

How to add variable category from code

Post by JockeD »

Thank's Edward
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How to add variable category from code

Post by Edward »

Hi Joakim,

Please let us know if you need any help.

Thank you.

Post Reply