Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Aderhold 30 posts 202 karma points
    Jan 05, 2020 @ 13:17
    Peter Aderhold
    0

    How to add PreValues programmatically into DropdownList in v8?

    Hi folks,

    I found some examples for v7 and earlier, but not for v8. Anyone knows how to do this?

    I have so far:

    public static void SetDataTypePreValues(int id, List<string> values)
        {
            var dataTypeService = Current.Services.DataTypeService;
            var dataType = dataTypeService.GetDataType(id); // this is the dropdownlist
            // and now???
    
        }
    

    Thank you for your help.

    Peter

  • Peter Aderhold 30 posts 202 karma points
    Jan 05, 2020 @ 14:22
    Peter Aderhold
    100

    What I did for now is:

    var valueList = (ValueListConfiguration)dataType.Configuration;
            var lastId = valueList.Items.LastOrDefault()?.Id;
            var newValueList = new List<ValueListConfiguration.ValueListItem>();
            var idCounter = lastId ?? 0;
            foreach (var val in values)
            {
                newValueList.Add(new ValueListConfiguration.ValueListItem
                {
                    Id = idCounter,
                    Value = val
                });
    
                idCounter++;
            }
            ((ValueListConfiguration)dataType.Configuration).Items.AddRange(newValueList);
            dataTypeService.Save(dataType);
    

    I don't know if this is the best way to do it, but at least it works.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies