views:

18

answers:

1

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?

+1  A: 

There's a DataSource property on DataGridView, ListBox, and ComboBox. 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.

Ben Voigt
+1/Accepted: A `DataGridView` looks like it should work fine - cheers.
Jon Cage
Also be aware that data binding in WinForms used the `IBindingList` interface (there's a `BindingList` class to use if you don't need custom behavior). I presume that `ObservableCollection` is a WPF thing.
Ben Voigt