日期:2014-05-18 浏览次数:20689 次
#region 判断某XML存不存在 /// <summary> /// 判断某XML存不存在 /// </summary> /// <param name="path">文件路径</param> /// <returns>布尔值</returns> public bool TheXmlIsExist(string path) { return File.Exists(path); } #endregion #region 读取一个XML文件,返回一个DataSet /// <summary> /// 读取一个XML文件,返回一个DataSet /// </summary> /// <param name="path">Xml文件路径</param> /// <returns>把xml文件读成DataSet取出</returns> public DataSet ReadTheXmlAndReturnDataSet(string path) { try { DataSet ds = new DataSet(); ds.ReadXml(path); return ds; } catch (Exception e) { throw e; } } #endregion
------解决方案--------------------
不会做,先做简单的习题。
------解决方案--------------------
[c#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TreeWpf
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
///
public partial class Window1 : Window
{
List<Info> MyInfoList = new List<Info>();
public Window1()
{
InitializeComponent();
MyInfoList = GetForumData();
AddTreeNode(0, null);
// MytreeView.ItemsSource = MyInfoList;
}
private void AddTreeNode(int parentID, TreeViewItem treeViewItem)
{
List<Info> result = (from forumInfo in MyInfoList
where forumInfo.ParendID == parentID
select forumInfo).ToList<Info>();
if (result.Count > 0)
{
foreach (Info Row in result)
{
TreeViewItem objTreeNode = new TreeViewItem();
objTreeNode.Header = Row.ForumName;
objTreeNode.DataContext = Row;
//此样式将会添加的所有叶子结点上
//objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;
//添加根节点
if (treeViewItem == null)
{
MytreeView.Items.Add(objTreeNode);
}
else
{
treeViewItem.Items.Add(objTreeNode);
}
AddTreeNode(Row.ForumID, objTreeNode);
}
}
}
public List<Info> GetForumData()
{
List<Info> forumList = new List<Info>();
forumList.Add(new Info() { ForumID = 1, ParendID = 0, ForumName = "笔记本版块" });
forumList.Add(new Info() { ForumID = 2, ParendID =