[Python] Complex DataBinding accepts as a data source either an IList or an IListSource....

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm a hobbyist developer writing python code scripts inside CAD software (to help design and build RC model aircraft). I recently upgraded the CAD software I use and in doing so, it upgraded the version of python from 2.7(Iron Python) to 3.9.10 (.NET Python). This conversion has introduced an issue in my code that I have not been able to find a resolution to.

    Put simply, I created a small user interface dialog using Windows.System.Forms components and try to assign values to a ListBox (using the DataSource property). Whilst it worked correctly in python 2.7, it produces an error in 3.9.10 as per the follow message -

    Complex DataBinding accepts as a data source either an IList or an IListSource. (Parameter 'value')

    An example of the code that generates this error is below:

    #! python 3

    import clr
    clr.AddReference("System.Windows.Forms")
    clr.AddReference("System.Drawing")

    from System.Windows.Forms import Application, Form, ListBox
    from System.Drawing import Point, Size

    # Define a simple class
    class Fruit:
    def __init__(self, name, color):
    self.Name = name # Property to display
    self.Color = color

    def __repr__(self):
    return f"{self.Name} ({self.Color})" # For debugging

    class MyForm(Form):
    def __init__(self):

    super().__init__()
    self.Text = "ListBox DataSource Example"
    self.Size = Size(300, 200)

    # Create a ListBox
    self.listbox = ListBox()
    self.listbox.Location = Point(20, 20)
    self.listbox.Size = Size(200, 100)

    # Create a list of objects
    fruits = [
    Fruit("Apple", "Red"),
    Fruit("Banana", "Yellow"),
    Fruit("Cherry", "Red"),
    Fruit("Date", "Brown")
    ]

    # Bind the ListBox to the list of objects
    self.listbox.DataSource = fruits
    self.listbox.DisplayMember = "Name" # Show the "Name" property

    # Add ListBox to form
    self.Controls.Add(self.listbox)

    # Run the application
    form = MyForm()
    Application.Run(form)


    If anyone can provide a solution to this problem it would be GREATLY appreciated. Many Thanks in Advance.

    Continue reading...

Compartilhe esta Página