2 Replies Latest reply: Apr 26, 2013 5:53 AM by Steffen Prendke RSS

    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.

        • Re: set selection by C# OCX

          Hello,

           

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

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

                          {

                              IVariableDescription v = qvReport.GetVariableDescriptions()[i];

                              //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 ...

          • Re: set selection by C# OCX

            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);