如何在 C++/CLI 中将 ListView 绑定到 ObservableCollection?
我有一个小应用程序,它允许用户选择多个文件,然后执行一些处理。我想我应该将文件收集在 String^
的 ObservableCollection
中(并且可能在以后将其扩展为完整的类)。
问题是我无法弄清楚如何将 ListView
绑定到 ObservableCollection
。我已向主窗体添加了一个属性:
protected:
ObservableCollection<String^>^ m_sourceFiles;
public:
property ObservableCollection<String^>^ SourceFileList
{
ObservableCollection<String^>^ get() {return m_sourceFiles;}
}
我见过的 C# / VB 实现的所有示例此时都切换为使用 XAML,但我不知道如何在 C++ 中执行此操作?我该去哪里?
I've got a small app which will allow the user to select a number of files and then perform some processing. I was thinking I'd collect the files in an ObservableCollection
of String^
(and probably expand this to a full class at a later date).
The problem is I can't work out how to bind the ListView
to the ObservableCollection
. I've added a property to the main form:
protected:
ObservableCollection<String^>^ m_sourceFiles;
public:
property ObservableCollection<String^>^ SourceFileList
{
ObservableCollection<String^>^ get() {return m_sourceFiles;}
}
All the examples I've seen for C# / VB implementations switch to using XAML at this point, but I can't see how to do that in C++? Where do I go from here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataGridView
、ListBox
和ComboBox
上有一个DataSource
属性。你能使用其中之一吗?System.Windows.Forms.ListView
不支持数据绑定。但是,您可以使用虚拟模式并处理 RetrieveVirtualItem 事件。There's a
DataSource
property onDataGridView
,ListBox
, andComboBox
. Can you use one of those?System.Windows.Forms.ListView
doesn't have support for data-binding. However, you can use virtual mode and handle the RetrieveVirtualItem event.