Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

set selection by C# OCX

Hey,

I want to set a certain selection by C# code in OCX. First I open some QVW Application and delete the current selection:

Application app = new Application();

Doc doc = app.OpenDoc(@"...\Example.qvw");

//clear current selection

doc.ClearAll();

Now, I want maybe set the selection on the dimension time. For instance the value day and month.

How can I achieve this.

Thank you for some tips.

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

this is the solution:

  Field fieldInvestmentRegion = doc.GetField("Investment Region");

IArrayOfFieldValues investFields = fieldInvestmentRegion.GetNoValues();

  investFields.Add();

  investFields[0].Text =  "Italy";

  investFields.Add();

  investFields[1].Text =  "Japan";

  fieldInvestmentRegion.SelectValues(investFields);

View solution in original post

2 Replies
Not applicable
Author

Hello,

                IList<QlikViewVariable> list = new List<QlikViewVariable>();

                for (int i = 0; i < qvReport.GetVariableDescriptions().Count; i++)

                {

                    IVariableDescription v = qvReport.GetVariableDescriptions();

                    //Console.WriteLine("Variable name : "+v.Name);

                    if (!(v.Name.Contains("filter")))

                    {

                        //Console.WriteLine(qvReport.GetVariable(v.Name).GetRawContent());

                        list.Add(new QlikViewVariable(v.Name, qvReport.GetVariable(v.Name).GetRawContent()));

                    }

                }

This might return you the variables from your report.

Now if you want to set any selection:

            foreach (KeyValuePair<string, object> p in <your selections>)

            {

                Variable v = qvReport.Variables(p.Key);

                if (v != null)

                {

                        //Console.WriteLine("Before modification content : " + v.GetContent().String);

                        v.SetContent(p.Value.ToString(), true);

                        //Console.WriteLine("Current content : " + v.GetContent().String);

                        variables = null;

                }

            }

            qvReport.Reload(0);

But, I'll ask a question to avoid the qvReport.Reload(0), because if you want to select several months and generate a report, you have to reload the whole report again which might take hours and hours ...

Not applicable
Author

Hi,

this is the solution:

  Field fieldInvestmentRegion = doc.GetField("Investment Region");

IArrayOfFieldValues investFields = fieldInvestmentRegion.GetNoValues();

  investFields.Add();

  investFields[0].Text =  "Italy";

  investFields.Add();

  investFields[1].Text =  "Japan";

  fieldInvestmentRegion.SelectValues(investFields);