我有一个简单的xml文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Tracks>
<Track>
<Name>Bye Bye Bye</Name>
<Album>No Strings Attached</Album>
<Artist>'N Sync</Artist>
<Genre>Teen Pop</Genre>
<Year>2000</Year>
<Duration>00:03:20.6640000</Duration>
<Location>\\psf\Home\Music\iTunes\iTunes Media\Music\'N Sync\No Strings Attached\01 Bye Bye Bye.mp3</Location>
</Track>
<Track>
我想将其绑定到ObjectListview。任何人都有任何简单的想法?
答案 0 :(得分:2)
AspectName
s set。ObjectListView.SetObjects()
将其绑定到集合。粗略的例子:
StreamReader sr = new StreamReader(Path.Combine(XMLFilePath, XMLFileName));
XmlSerializer x = new XmlSerializer(typeof(ClassTrack));
ClassTrack MyTrack = (ClassTrack)x.Deserialize(sr);
// Deserialize other XML as necessary
List<ClassTrack> TrackCollection = new List<ClassTrack>();
TrackCollection.Add(MyTrack);
// Add other MyTrack objects to collection
olvTrackList.SetObjects(TrackCollection);