日期:2014-05-18  浏览次数:20979 次

求助!关于WPF中ListView绑定DataTable问题
C# code
TreeViewItem selectedItem = (TreeViewItem)folderTreeView.SelectedItem;
            string selectedPath = (string)selectedItem.Tag;
            string[] files = Directory.GetFiles(selectedPath);
            this.fileListView.Items.Clear();

            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Name",Type.GetType("System.String"));
            dataTable.Columns.Add("LastModifiedTime",Type.GetType("System.String"));
            dataTable.Columns.Add("Size",Type.GetType("System.String"));

            foreach(string file in files)
            {
                FileInfo fileInfo = new FileInfo(file);
                string[] items= new string[] { fileInfo.Name, fileInfo.LastWriteTime.ToString(), fileInfo.Length.ToString() };
                dataTable.Rows.Add(items[0], items[1], items[2]);
            }
            this.fileListView.DataContext = dataTable;


我写完后调试无法显示出内容,listView中还是没有数据显示,求解决!!!

------解决方案--------------------
this.fileListView.DataContext = dataTable;

先把基础弄明白再动手,WPF绑定是怎么玩的你知道吗?