未处理的“System.OutOfMemoryException”类型的异常出现在system.windows.forms.dll中
private void xqck_Load(object sender, System.EventArgs e)
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = this.ds.Tables[0].TableName;
this.dataGrid1.TableStyles.Add(ts);
sendStrSQL = "SELECT ID AS 编号, Name FROM tZD where Parent = 0 ";
this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
this.dataGrid1.DataSource = ds;
treeView1.BeginUpdate();
for (int i=0;i <ds.Tables[0].Rows.Count;i {
TreeNode node=new TreeNode(ds.Tables [0].Rows [i][1].ToString ().Trim());
treeView1.Nodes.Add(node);
getSubNode(node);
}
treeView1.EndUpdate();
}
private void getSubNode(TreeNode PathName)
{
treeView1.BeginUpdate();
PathName.Nodes.Clear();
string strFullPath = PathName.FullPath;
string id = PathName.Tag.ToString();
sendStrSQL = "SELECT ID AS 编号, Name FROM tZD where Parent = " + id;
this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
this.dataGrid1.DataSource = ds;
for (int i=0;i <ds.Tables[0].Rows.Count;i++)
{
TreeNode node = new TreeNode(ds1.Tables [0].Rows [i][1].ToString().Trim());
node.Tag = ds.Tables [0].Rows [i][0].ToString();
PathName.Nodes.Add( "node ");
}
treeView1.EndUpdate();
}
以上的代码是生成一个目录树,但运行后出现如提的错误提示,请问这是什么错误?如何解决,谢谢
------解决方案--------------------内存溢出,估计是哪里出现了死循环之类的,你试试注视getSubNode方法中treeView1.BeginUpdate();和treeView1.EndUpdate();
------解决方案--------------------可能是pathname没有实例化。跟踪一下看它有没有值