Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
765
How to dynamically populate Ultracombo#2 based on value selected in Ultracombo#1?
posted
I have a main Windows form whose code-behind "fills" a data table called "Site".  It is filled based on the user's office.  This is working correctly.
BUT...I have a button that launches another form which contains 2 Ultracombo objects.  Ultracombo#1 provides a list of offices.  DataSource is "officebindingsource", DataTable = "Office", DisplayMember is "office_name" and ValueMember is "office_code".  Ultracombo#2 should provide a list of sites based on the selected office (in Ultracombo#1).  Ultracombo #2's DataSource is "sitebindingsource", DataTable = "Site", DisplayMember is "site_description" and ValueMember is "site_id".  In Ultracombo#2, I set the DataBindings/Value = "officebindingsource - office_code" (bindingsource for Ultracombo#1).  I have one method that checks when the value of Ultracombo#1 is changed:

private void comboOffice_ValueChanged(object sender, EventArgs e)
{
      //Check if Office in Ultracombo#1 was changed        
       if (comboOffice.Value != null)
        {
            string office = comboOffice.Value.ToString();
           //comboCurrLoc is the 2nd Ultracombo on the form, should only display sites based on the user's selected office
            comboCurrLoc.Rows.ColumnFilters.ClearAllFilters();
            comboCurrLoc.Rows.ColumnFilters[
"OFFICE_CODE"].FilterConditions.Add(FilterComparisionOperator.Equals, office);
            comboCurrLoc.Value =
null;
}

I feel that I'm close, but when I change the value of the office in Ultracombo#1, the second combobox is blank.  Is there something else I should be adding to make the 2nd Ultracombo display the correct values?

 

  • 469350
    Verified Answer
    Offline posted

    When you say "the second combo is blank", what exactly do you mean? There are no rows on the list? Do you still see the column headers? If there are column headers and no rows, then it sounds to me like you are filtering out ALL of the rows. If the OFFICE_CODE value a string field? Seems like this is some kind of key field and is probably numeric. If that's the case, why are you converting the filter value to a string? 

    • 765
      posted in reply to Mike Saltzman

      The second combo does not display any rows, but does show the column headers.  The OFFICE_CODE value is a vachar2(3) data type (Oracle), that's why I'm converting it to a string.  So I understand, if I use this statement:

      comboCurrLoc.Rows.ColumnFilters["OFFICE_CODE"].FilterConditions.Add(FilterComparisionOperator.Equals, office);

      This will filter rows so that only the rows that have the specific office value (passed in) are displayed, correct?  I assume if I do a Row.Count() before and after this statement, I should see if it's being applied correctly? 

      I forgot to mention that I also changed the .DisplayLayout.Bands(0).Override.RowFilterAction property to "HideFilteredOutRows".  Could this be causing a problem?

       

      • 765
        posted in reply to Mike Saltzman

        Mike,

        This makes sense to me, although, I found a work-around for now.  I will revisit this later and check the DataTypes.

        Thank you,
        Chris

         

         

        • 469350
          Verified Answer
          Offline posted in reply to Chris

          Hi,

          Well, if you set the filter and all the rows disappear, the obvious implication is that there are no rows on the list that match the value you applied for the filter. My original guess was that maybe your data was numeric and you were filtering by a string and therefore nothing matched up. 

          There are no fixed-length strings in DotNet, though, so I wonder what DataType the column in the dropdown is actually using. Maybe it's not a string. Or maybe the issue is that the strings on the dropdown list are fixed-length, so your filter needs to append extra space so that you make sure it matches the item on the list exactly.