TreeView节点重命名保存问题
TreeView里面的节点是从数据库里面搜索出来的,新建了一个弹出菜单,用来对节点进行新添/删除/重命名操作,这是TreeView数据节点绑定方法:
private void bindertoviewtree(TreeView treeView)
{
treeView.Nodes.Clear();
SqlConnection conn = new SqlConnection( "server=(local);database=phonemanage;Integrated Security=True ");
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter( "select * from lb ", conn);
sda.Fill(tblinfo);
DataTable temptbl = tblinfo.Copy();
DataView viewinfo = new DataView(temptbl);
viewinfo.RowFilter = "id=1 ";
if (viewinfo.Count > 0)
{
foreach (DataRowView myrow in viewinfo)
{
string name = myrow[ "name "].ToString().Trim();
treeView.Nodes.Add(myrow[ "id "].ToString(), name);
PopulateTreeView(name, treeView.Nodes[0], myrow);
treeView.SelectedNode = treeView.Nodes[0];
treeView.SelectedNode.Expand();//展开所有结点
}
}
tblinfo.Clear();
conn.Close();
}
当重命名的时候: treeView.LabelEdit=true;
因为是要保存到