gpt4 book ai didi

c# - 无法从 comboBox c# 中删除项目

转载 作者:行者123 更新时间:2023-12-02 22:03:31 25 4
gpt4 key购买 nike

我有一个

public ObservableCollection<Canal> channelList { get; set; }

(我也试过一个List,Canal是一个类)。我绘制了来自 channel 内列表的一些数据。我还有一个显示每个 channel 名称的组合框。

我的问题是我不能这样做:

comboBox1.Items.Clear();

因为它给我“在使用 ItemsSource 时操作无效。改为使用 ItemsControl.ItemsSource 访问和修改元素。”错误。

数据已绑定(bind),但我不知道这是否重要。谢谢

最佳答案

MSDN页面,它说:

When ItemsSource is in use, setting the property to null removes the collection and restores usage to Items, which will be an empty ItemCollection.

因为 ItemsSource 正在使用中,您必须将其设置为 null 才能清除项目:

comboBox1.ItemsSource = null;

关于c# - 无法从 comboBox c# 中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com