Search code examples
c#winformsqlikviewocx

QlikView OCX in .NET setting a field value removes previous selection


I have setup the QlikView OCX to work in my C# winforms app. I have gathered all possible field values for the specific fields that I am looking to target. I have created selectors that hold that data in .NET controls. The user would make selections within the .NET controls and click a button to set the field values.

I can easily set a field value for one of the fields. For example I am having no problem setting the date when that is the only option selected. However, if the user then makes a "company" selection along with the date selection, only the company selection is set. I can see in my current selections object that the date was initially set, very briefly, then when the company gets set it overrides the previous date selection. All I am left with is just the company selection, no date.

Here is the code I have:

private void SetValues()
{
    Field dateField = qvDoc.GetField("Date");
    dateField.Clear();
    IArrayOfFieldValue selectedDateFields = tradeDateField.GetNoValues();
    selectedDateFields.Add();
    selectedDateFields[0].Number = Convert.ToDouble(qvDoc.Evalueate("=num('" + (DateTime)ddlDate.EditValue _ "')"));
    selectedDateFields[0].IsNumeric = true;
    dateField.SelectValues(selectedDateFields);

    Field companyField = qvDoc.GetField("Company");
    companyField.Clear();
    IArrayOfFieldValue selectedCompanyFields = companyField.GetNoValues();
    for (int i = 0; i < selectedCompanies.Count; i++)
    {
        selectedCompanyFields.Add();
        selectedCompanyFields[i].Text = selectedCompanies[i];
    }
    companyField.SelectValues(selectedCompanyFields);
}

When running that method I would expect to see my current selections set with a date and company. Only the company is being set. What am I missing? Why does this remove my previous selection?


Solution

  • The reason this was occurring is due to the possible selections. For my example, I am pre-populating the datasources with the possible values for the date and company with no selections made. When I select a trade date, there was no re-evaluation on the possible selections for company. So if I selected a trade date that did not hold any records for a particular company that day, selecting the company removes the trade date filter since it is not a possible selection.

    I fixed this by checking for possible selections for each datasource when either data source has a selection made.