1.7k questions

3.2k answers

1.7k comments

398 users

Categories

1.7k questions

3.2k answers

1.7k comments

398 users

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?TocPath=Simple%20Data%20Lists|_____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 _countryid_ValueChange (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

}

}
___
6. compiled and deployed/load all related files for debug.
7. when run debug mode, after select a country it does went inside _countryid_ValueChanged 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 by mnguyen (117 points)

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 _addresscountryid_ValueChanged(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 by abeldebela (232 points)

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

...