Page 1 of 1

How to add variable category from code

Posted: Thu Oct 01, 2009 2:51 am
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

How to add variable category from code

Posted: Thu Oct 01, 2009 7:36 am
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.

How to add variable category from code

Posted: Tue Oct 06, 2009 2:08 am
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



How to add variable category from code

Posted: Tue Oct 06, 2009 7:26 am
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.

How to add variable category from code

Posted: Tue Oct 06, 2009 8:56 am
by JockeD
Thank's Edward

How to add variable category from code

Posted: Wed Oct 07, 2009 3:13 am
by Edward
Hi Joakim,

Please let us know if you need any help.

Thank you.