c#“.datasource”未显示在框中

c# ".datasource" not showing in the box

每当我输入 .DataSource 时,它的底部总是显示红色或出现错误:

'ListView' does not contain a defenition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'ListView' could be found (are you missing a using directive or an assembly reference?)

public Form4()
{
    InitializeComponent();

    lstProductsChosen.DataSource = products;
}

我该怎么办?我需要添加参考吗?

ListView 没有 DataSource 属性.

ListBox 有一个。如果您使用 ListBox 而不是您的代码应该工作。

如果您使用 WPF,您会在 link 后面找到一个 Simple ListView data binding 示例。

如果您使用的是 WinForms,请查看 Hans Passantthis short and consice answer