How can I get the contents of the Value List?

I was able to connect the ValueList to the first input of the C# component and get the ListItem, but I can’t figure out how to get the key/value combination of the ValueList from here.

Please let me know if there is any method or reference.

var input = Component.Params.Input[0];
Grasshopper.Kernel.Special.GH_ValueList vallist;
vallist = input.Sources[0].Attributes.DocObject as Grasshopper.Kernel.Special.GH_ValueList;
A = vallist.ListItems.Value;

getValueListContents.gh (3.6 KB)

Hi
vallist.ListItems returns GH_ValueListItem,You can use Linq to get the value of GH_ValueListItem,like this

var input = Component.Params.Input[0];
        Grasshopper.Kernel.Special.GH_ValueList vallist;
        vallist = input.Sources[0].Attributes.DocObject as Grasshopper.Kernel.Special.GH_ValueList;
        if (vallist != null)
        {
          A = vallist.ListItems.Select(o => o.Value);
        }

getValueListContents++.gh (4.3 KB)

1 Like

thank you for your quick response!
And I am very pleased with the detailed explanation
I was able to get the name as well by using “o.Name”!
Thank you very much…!!