0
層次結構我已經使用這個代碼填充一個TreeView:如何生成樹狀
private void updateTree()
{
treeView1.Nodes.Clear();
List<TreeNode> graphicsNodes = new List<TreeNode>();
foreach (Graphic graphic in graphics)
{
List<TreeNode> templateNodes = new List<TreeNode>();
foreach (Template template in graphic.templates)
{
List<TreeNode> aliasNodes = new List<TreeNode>();
foreach(Alias alias in template.aliases)
{
aliasNodes.Add(new TreeNode(alias.aliasName + ": " + alias.aliasValue));
}
templateNodes.Add(new TreeNode(template.templateName, aliasNodes.ToArray()));
}
graphicsNodes.Add(new TreeNode(graphic.fileName.Replace(".g", ""), templateNodes.ToArray()));
}
treeView1.Nodes.Add(new TreeNode("Graphics", graphicsNodes.ToArray()));
}
操作,重命名和刪除一些在TreeView這些元素之後,纔有可能重建我Grapics結構與新值?
這種結構是建立使每個圖形有許多模板和每個模板都有許多別名,該代碼的定義如下:
public class Graphic
{
public string filePath;
public string fileName;
public List<Template> templates;
public Graphic(List<Template> _templates, string fpath, string fName)
{
templates = _templates;
fileName = fName;
filePath = fpath;
}
}
public class Template
{
public List<Alias> aliases;
public string templateName;
public Template(string instString, string userdataString)
{
templateName = (instString.Replace("inst ", "").Replace(" 0 0", "")).Replace(" ","");
aliases = new List<Alias>();
string[] aliasStrings = userdataString.Replace("\"","").Split(new string[1] { "text_alias" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string segment in aliasStrings)
{
if (segment.Contains("userdata")) { continue; }
string aliasString = "text_alias" + segment;
string[] sections = aliasString.Split('^');
aliases.Add(new Alias(sections[0].Replace("text_alias=", ""), (sections[1].Replace("text_exp_flag=", "") == "1"), sections[2].Replace("alias_new_name=", ""), sections[3].Replace("alias_value=", ""))); //Sorry!
}
}
}
public class Alias
{
public string aliasName;
public string aliasValue;
public string newName;
public bool expectedFlag;
public Alias(string name, bool expected, string nName, string value)
{
aliasName = name;
aliasValue = value;
newName = nName;
expectedFlag = expected;
}
}
如果這是不容易實現,這將是對的最佳方式從不同的角度來看待這個問題?
在此先感謝!
任何機會,我能有一個快速的解釋,什麼實際上做真實嗎? –
代碼從SQL數據庫繪製層次結構,DataSet對象dst在表格結構中包含Schema,在每個for循環迭代中,它繪製schemaname,然後獲取columnName,然後創建一個childNode來排列ColumnNames。這裏col是columnindex – Angad
我的層次結構不在sql db中 –