public override bool IsLeaf(TreePath treePath)
 {
     DataRowNode n = treePath.LastNode as DataRowNode;
     if (n.Row["IsFolder"] == DBNull.Value)
         return false;
     return !Convert.ToBoolean(n.Row["IsFolder"]);
 }
		public System.Collections.IEnumerable GetChildren(TreePath treePath)
		{
			if(treePath.IsEmpty())
				return _list;
			else
				return null;
		}
		public TreePathEventArgs(TreePath path)
		{
			if(path==null)
				throw new ArgumentNullException();

			_path=path;
		}
		public Node FindNode(TreePath path)
		{
			if(path.IsEmpty())
				return _root;
			else
				return FindNode(_root, path, 0);
		}
        public override System.Collections.IEnumerable GetChildren(TreePath treePath)
        {
            List<DataRowNode> items = new List<DataRowNode>();

            if (treePath.IsEmpty() )
            {
                items.Add(m_root);
            }
            else
            {
                DataRowNode n = treePath.LastNode as DataRowNode;

                DataRow row = n.Row;
                int id = Convert.ToInt32(row[m_IDColumnName]);

                DataRow[] rows = m_table.Select("ParentID = " + id+" and "+m_IDColumnName+" <> "+id);
                foreach (DataRow r in rows)
                {
                    DataRowNode node = new DataRowNode(r,r["Name"].ToString());
                    node.Row = r;
                    //SampleApp.Properties.Resources.ResourceManager.
                    //node.Icon = new Bitmap(SampleApp.Properties.Resources.Records,new Size(15,15));
                    items.Add(node);
                }
            }
            return items;
        }
		public bool IsLeaf(TreePath treePath)
		{
			Node node=FindNode(treePath);
			if(node!=null)
				return node.IsLeaf;
			else
				throw new ArgumentException("treePath");
		}
		public System.Collections.IEnumerable GetChildren(TreePath treePath)
		{
			Node node=FindNode(treePath);
			if(node!=null)
				foreach(Node n in node.Nodes)
					yield return n;
			else
				yield break;
		}
		public System.Collections.IEnumerable GetChildren(TreePath treePath)
		{
			if (treePath.FullPath.Length < 3)
				for (int i = 0; i < 5; i++)
				{
					if (treePath.FirstNode != null)
						Thread.Sleep(1000);
					yield return new Node("item" + i.ToString());
				}
			else
				yield break;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="parent">Path to a parent node</param>
		/// <param name="indices">Indices of children in parent nodes collection</param>
		/// <param name="children">Child nodes</param>
		public TreeModelEventArgs(TreePath parent, int[] indices, object[] children)
			: base(parent)
		{
			if(children==null)
				throw new ArgumentNullException();

			if(indices!=null&&indices.Length!=children.Length)
				throw new ArgumentException("indices and children arrays must have the same length");

			_indices=indices;
			_children=children;
		}
		private Node FindNode(Node root, TreePath path, int level)
		{
			foreach(Node node in root.Nodes)
				if(node==path.FullPath[level])
				{
					if(level==path.FullPath.Length-1)
						return node;
					else
						return FindNode(node, path, level+1);
				}
			return null;
		}
        //public event EventHandler<TreeModelEventArgs> NodesChanged;

         //public event EventHandler<TreeModelEventArgs> NodesInserted;

        //public event EventHandler<TreeModelEventArgs> NodesRemoved;

        //public event EventHandler<TreePathEventArgs> StructureChanged;


        public void AddChild(TreePath parent, string text)
        {
            DataRowNode n = parent.LastNode as DataRowNode;
             
           DataRow r =   m_table.NewRow();
           r["ID"] = GetNextID();
           r["ParentID"] = n.Row["ID"];
           r["IsFolder"] = false;
           r["Name"] = text;
           r["Tag"] = "";
           m_table.Rows.Add(r);
           DataRowNode child = new DataRowNode(r, text);
           OnStructureChanged(new TreePathEventArgs(parent));
        }
		public System.Collections.IEnumerable GetChildren(TreePath treePath)
		{
			List<BaseItem> items = null;
			if (treePath.IsEmpty())
			{
				if (_cache.ContainsKey("ROOT"))
					items = _cache["ROOT"];
				else
				{
					items = new List<BaseItem>();
					_cache.Add("ROOT", items);
					foreach (string str in Environment.GetLogicalDrives())
						items.Add(new RootItem(str, this));
				}
			}
			else
			{
				BaseItem parent = treePath.LastNode as BaseItem;
				if (parent != null)
				{
					if (_cache.ContainsKey(parent.ItemPath))
						items = _cache[parent.ItemPath];
					else
					{
						items = new List<BaseItem>();
						try
						{
							foreach (string str in Directory.GetDirectories(parent.ItemPath))
								items.Add(new FolderItem(str, parent, this));
							foreach (string str in Directory.GetFiles(parent.ItemPath))
							{
								FileItem item = new FileItem(str, parent, this);
								items.Add(item);
							}
						}
						catch (IOException)
						{
							return null;
						}
						_cache.Add(parent.ItemPath, items);
						_itemsToRead.AddRange(items);
						if (!_worker.IsBusy)
							_worker.RunWorkerAsync();
					}
				}
			}
			return items;
		}
		public override IEnumerable GetChildren(TreePath treePath)
		{
			if(Comparer!=null)
			{
				ArrayList list=new ArrayList();
				IEnumerable res=InnerModel.GetChildren(treePath);
				if(res!=null)
				{
					foreach(object obj in res)
						list.Add(obj);
					list.Sort(Comparer);
					return list;
				}
				else
					return null;
			}
			else
				return InnerModel.GetChildren(treePath);
		}
		public override IEnumerable GetChildren(TreePath treePath)
		{
			return _list;
		}
		public override bool IsLeaf(TreePath treePath)
		{
			return true;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="parent">Path to a parent node</param>
		/// <param name="children">Child nodes</param>
		public TreeModelEventArgs(TreePath parent, object[] children)
			: this(parent, null, children)
		{
		}
		public abstract bool IsLeaf(TreePath treePath);
		public abstract System.Collections.IEnumerable GetChildren(TreePath treePath);
		public bool IsLeaf(TreePath treePath)
		{
			return false;
		}
		public bool IsLeaf(TreePath treePath)
		{
			return treePath.LastNode is FileItem;
		}
		public bool IsLeaf(TreePath treePath)
		{
			return true;
		}
		public override bool IsLeaf(TreePath treePath)
		{
			return InnerModel.IsLeaf(treePath);
		}
		public TreePathEventArgs()
		{
			_path=new TreePath();
		}