Hi, I'm trying to create a drop down programatically, but I'm having some issues. I've been googling around quite a bit, and found something that should work, but for some reason doesn't. Here is what I have currently:
Dictionary<string, PreValue> dictionary = new Dictionary<string, PreValue>();
dictionary.Add("firstOption", new PreValue("1"));
dictionary.Add("SecondOption", new PreValue("2"));
var dataType = new DataTypeDefinition(-1, "Umbraco.DropDown.Flexible");
dataType.Name = "MyDropDown";
Services.Save(dataType);
Services.SaveDataTypeAndPreValues(dataType, dictionary);
This works with other data types that require prevalues, such as for example Radio List, but for the drop down it doesn't for some reason, and I just get a DB mapping error.
So after some more Googling I finally found the answer. The above solution is almost complete, but it is missing a value which was not quite obvious. You need to specify if it should be a multiple picker or not like so:
Dictionary<string, PreValue> dictionary = new Dictionary<string, PreValue>();
dictionary.Add("firstOption", new PreValue("1"));
dictionary.Add("SecondOption", new PreValue("2"));
dictionary.Add("multiple", new PreValue("0"));
var dataType = new DataTypeDefinition(-1, "Umbraco.DropDown.Flexible");
dataType.Name = "MyDropDown";
Services.Save(dataType);
Services.SaveDataTypeAndPreValues(dataType, dictionary);
Not including the "multiple" value will still create the drop down, but it will be corrupted and unusable. Hope this helps anyone stuck on this in the future.
Creating a Drop Down programatically
Hi, I'm trying to create a drop down programatically, but I'm having some issues. I've been googling around quite a bit, and found something that should work, but for some reason doesn't. Here is what I have currently:
This works with other data types that require prevalues, such as for example Radio List, but for the drop down it doesn't for some reason, and I just get a DB mapping error.
So after some more Googling I finally found the answer. The above solution is almost complete, but it is missing a value which was not quite obvious. You need to specify if it should be a multiple picker or not like so:
Not including the "multiple" value will still create the drop down, but it will be corrupted and unusable. Hope this helps anyone stuck on this in the future.
For reference, I found the solution in this file: https://github.com/umbraco/OurUmbraco/blob/master/OurUmbraco/Our/MigrationsHandler.cs
is working on a reply...