List Value - automatic update

Hi, to all in this awesome forum.
I am trying to create a couple of GH components (C# in VS 2019) which cope with layers in active Rhino document.
My goal is to create a two kinds of value lists.

First - I would like to create a value list should be able to offer to its users list of actual layers in the document for selection. I was able to create a value list which offers this layer list (see code bellow). However, I am not able to update this value list when layers are modified (e.g. Renamed, deleted, added). Automatic update.

Second - I would like to code a empty value list which will be able to get input list and offer items in this list for selection. I know this component exist in HUMAN plugin. I tried to understand its code but it is quite complicated for me. I know I can just use this component but my side goal is to understand principles of coding into Rhino and GH. Therefore, I would like simplify it recreate code on my own. However, I am stuck here.

Thanks for any kind of help.


Prague, CZ

using System;
using System.Collections.Generic;
using Rhino.DocObjects;
using Grasshopper.Kernel.Special;

namespace Bridge_modelling
    public class ValueListLayers : ValueListMother
        // Fields

        // Methods
        public ValueListLayers()
            List<string> L1 = new List<string>();
            List<string> L2 = new List<string>();
            this.keys = L1;
            this.values = L2;
            this.Name = "Layers selector";
            this.NickName = "LayerSelector";
            this.Description = "Value list for layer select";
            foreach (Layer layer in Rhino.RhinoDoc.ActiveDoc.Layers)
                if (!layer.IsDeleted)
                    L2.Add("\"" + layer.Name + "\"");
            for (int i = 0; i < this.keys.Count; i++)
                base.ListItems.Add(new GH_ValueListItem(this.keys[i], this.values[i]));

        public override Guid ComponentGuid =>
            new Guid("e477c418-0275-4915-a664-581380d4b648");

        protected override System.Drawing.Bitmap Icon
                //You can add image files to your project resources and access them like this:
                // return Resources.IconForThisComponent;
                return Properties.Resources.List_objects;

You need to subscribe to the appropriate events. RhinoDoc has a LayerTableEvent which will probably do the trick. You’ll also need to keep track of changes to the current active document.