How to Select and Delete a connected input component?

My question applies to both GHPY and C# code for my custom GH Component.

Is there a way to select and delete a connected input component that feeds into another component?

For example, in our GHPY component, when objects are connected to it, we create an automated Values List that can select the objects by type. Currently, when the object list is updated, we disconnect and regenerate the custom Values List. This means that the old values list is sitting dead on the canvas. Is there a way to delete it? I cannot find anything in the Grasshopper SDK for it nor examples anywhere.

Desired Functionality
When the geometry changes, we want to either

  1. Update the custom Values List component – if it’s been already created
  2. Delete the old Values List component and generate the new one.

Example of the GHPY functions in the component
If anyone has C# examples, that’s also fine… or to point me to the right Class and Methods to use.

    def remove_uim_value_list(self, sender, e):
        if (e.Type == Grasshopper.Kernel.GH_ObjectEventType.Sources):

    def update_uim_value_list_filer(self, doc):
        if self.Params.Input[1].SourceCount > 0:
            sources = self.Params.Input[1].Source
            self.OnPingDocument().RemoveObjects(sources, False)

        value_list = Grasshopper.Kernel.Special.GH_ValueList()

        inputcount = self.Params.Input[1].SourceCount
        value_list.Attributes.Pivot = System.Drawing.PointF(float(self.Attributes.DocObject.Attributes.Bounds.Left - value_list.Attributes.Bounds.Width - 100), float( self.Params.Input[1].Attributes.Bounds.Y + inputcount * 30))

        value_list.NickName = self.input_entity_name

        for k in self.keys:
            item = Grasshopper.Kernel.Special.GH_ValueListItem(k, "\"" + k + "\"")

        self.OnPingDocument().AddObject(value_list, False)
1 Like

see Automated Value list C# Grasshopper

If inside that “ExpireIt” method you add:

IGH_Param vl = this.Component.Params.Input[0].Sources[0];

it deletes the value list component…