1,627 questions

3,174 answers

1,701 comments

477 users

call _stateid.ResetDataSource() does not refresh/reload State list from Dynamically Populate Simple Data Lists

0 votes

I'm following the instruction on dev guide about dynamically populate simple data lists.

https://www.blackbaud.com/files/support/guides/infinitydevguide/infsdk-developer-help.htm#../Subsystems/simpleda-developer-help/Content/InfinitySimpleDataLists/coDynamicallyPopulatingSimpleDataLists.htm%3FTocPath%3DSimple%2520Data%2520Lists%7C_____2

created :
1. 2 simple data list: country List, state list; state list has parameter of country id...
2. 1 custom table to add countryid, stateid so that I can do save from add data form.
3. 1 custom add data form with 2 fields Country, State with simple datalists from (1).
4. Using uiwizard to create uimodel for for simple add data form.
5. I added private void countryidValueChange (object sender, ValueChangedEventArgs e)
to call _stateid.ResetDataSource()
my model.cs :


using System;
using System.Collections.Generic;
using Blackbaud.AppFx.UIModeling.Core;

namespace FSUCRMCustom.UIModel
{

public partial class CustomCountryStateAddDataFormUIModel
{

    private void CustomCountryStateAddDataFormUIModel_Loaded(object sender, Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs e)
    {

    }

region "Event handlers"

    partial void OnCreated()
    {
        this.Loaded += CustomCountryStateAddDataFormUIModel_Loaded;
        _countryid.ValueChanged += _countryid_ValueChanged;
    }

    private void _countryid_ValueChanged (object sender, ValueChangedEventArgs e)
    {
        if (_countryid.Model.RootUIModel().Loading != true)
        {
            _stateid.Value = string.Empty;
        }
        _stateid.ResetDataSource();
    }

endregion

}

}


  1. compiled and deployed/load all related files for debug.
  2. when run debug mode, after select a country it does went inside countryidValueChanged method and did step over _stateid.ResetDataSource() as expected, but State Abbriviation list still listing the same default values list

Is there anything else I've missed? I'm stuck on this for couple days try to make it work but no luck so it's time to ask a question. Thank you Mydieu

asked Sep 28 by mnguyen (111 points)   2 3 8

1 Answer

0 votes

If you are trying to tie state value with country, first you will need to set the relationship in the catalog item.

  <d1p1:FormField FieldID="ADDRESS_STATEID" DataType="Guid" Caption="State">
    <d1p1:SimpleDataList SimpleDataListID="7fa91401-596c-4f7c-936d-6e41683121d7">
      <d1p1:Params>
        <d1p1:Param ID="COUNTRYID">
          <d1p1:Value>Fields!ADDRESS_COUNTRYID</d1p1:Value>
        </d1p1:Param>
      </d1p1:Params>
    </d1p1:SimpleDataList>
  </d1p1:FormField>

Then in the UI Model, you define a void function that you call on change event of ADDRESS_COUNTRYID

private void addresscountryidValueChanged(object sender, ValueChangedEventArgs e)
{
CountrySelection(addresscountryid.Value);
_addressstateid.GetItemFromValue(
addresscountryid);
_addressstateid.ResetDataSource();
}

private void CountrySelection(System.Guid paraCountryId)
{

if (paraCountryId == System.Guid.Empty)
{
    _addressstateid.Value = System.Guid.Empty;
    _addressstateid.Enabled = false;
}
else
{
    _addressstateid.Enabled = true;
    _addressstateid.GetItemFromValue(_addresscountryid);
    _addressstateid.ResetDataSource();
}

}

answered Sep 29 by abeldebela (232 points)   1 4 14

Thank you abeldebela!
I followed your advised but it didn't work at first. turned out I also need to add parameter call from codegen as well:
//
//stateid
//
_stateid.Name = "STATEID";
_stateid.Caption = "State";
SimpleDataListField stateid = this.
stateid;
Guid guid1 = new Guid("2c6c53f4-ba1b-482d-8674-b5a9fc3f9419");
Guid guid2 = guid1;
stateid.SimpleDataListId = guid2;
this.stateid.Parameters.Add(new SimpleDataListParameter("COUNTRYID", "Fields!COUNTRYID"));
this.Fields.Add((UIField) this.
stateid);

Quick Question:

   is there a reason you call the following 
          _addressstateid.GetItemFromValue(addresscountryid);
         _addressstateid.ResetDataSource();
  2 times? 
         1st time in the else case of SelectCountry function;
          2nd time from addresscountryidValueChanged after they both get call from SelectCountry?

Thank you again,
Mydieu

Looks like you solved the issue. For the record, the codegen files are a reflection of the XML at the time the ui wizard was first executed. If you change the catalog spec, you can load it and use Tools>Refresh UI Model to re-generate the codegen files.

...