Custom ValueList in Grasshopper giving null output

Hello :),
I am developing a grasshopper plugin, and one of my components is a Custom ValueList which should allow the user to select an item, to be used as input for other components.
My code works, in the sense that the component is loaded and I can choose an element from the list, but it seems to give ‘null’ as an output when I connect it to a panel. Is this normal ?
Is my GH_ValueListItem well defined ?
Below is my code.
`

public class ProjectsDropDownList : GH_ValueList
    {
        public ProjectsDropDownList()
        {
            Category = "MyCatgory";
            SubCategory = "My SubCategroy";
            NickName = "projs";
            MutableNickName = false;
            Name = "proj Picker";
            Description = "Provides a proj picker";

            ListMode = GH_ValueListMode.DropDown;
        }

        public override Guid ComponentGuid => new Guid("f151bfa4-d60b-4267-9eb0-184edc0ae091");

        protected override void CollectVolatileData_Custom()
        {
            var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList();
            ListItems.Clear();

            
            var ProjList = MyprojList.Populate();
            foreach (var proj in ProjList)
            {

                var item = new GH_ValueListItem(proj.GetName(), proj.ObjectId.ToString());
                item.Selected = selectedItems.Contains(item.Expression);
                ListItems.Add(item);
            }


            if (selectedItems.Count == 0 && ListMode != GH_ValueListMode.CheckList)
            {
                foreach (var item in ListItems)
                    item.Selected = item.Expression == ProjList.FirstOrDefault().ObjectId.ToString();
            }


            base.CollectVolatileData_Custom();
        }
    }

`
Thanks a lot in advance

Why not just fill it up the list once in the constructor?

    public ProjectsDropDownList()
    {
      Category = "TEST";
      SubCategory = "TEST";
      NickName = "Projects";
      MutableNickName = false;
      Name = "Project Picker";
      Description = "Provides a project picker";

      ListMode = GH_ValueListMode.DropDown;

      ListItems.Clear();
      var projects = new[] { "Aaaa", "Bbbb", "Cccc", "Dddd" }; // MyprojList.Populate();
      foreach (var project in projects)
      {
        var item = new GH_ValueListItem(project, '"' + project + '"');
        item.Selected = project.StartsWith("A");
        ListItems.Add(item);
      }
    }

    public override Guid ComponentGuid => new Guid("f151bfa4-d60b-4267-9eb0-184edc0ae091");
  }
1 Like

Perfect, it solved it.
It’s a Rhino.inside project, I looked at examples from Rhino.inside.Revit, didn’t know I could fill up my list directly in the constructor. Looks simpler this way.
Thanks a lot, David!

1 Like