Answer the question
In order to leave comments, you need to log in
Is it possible to convert such a class to a TreeView?
There is a class like this:
public class Block
{
public string title; // название класса
public Dictionary<string, object> property; // свойства, object может быть string или List<string>
public Block parent; // ссылка на блок родителя
}
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "firmsmaterials",
"access_type": "ALL",
"rows": 11,
"filtered": 100
}
}
}
StringBuilder arrProperties;
TreeViewItem tvItem, ptvItem = new TreeViewItem { Header = "root"};
foreach (Block b in blocks)
{
tvItem = new TreeViewItem { Header = b.title };
foreach(KeyValuePair<string, object> i in b.property)
{
if (i.Value is string || i.Value is int)
{
tvItem.Items.Add(new TreeViewItem { Header = i.Key + " : " + i.Value });
}
else if (i.Value is List<string>)
{
arrProperties = new StringBuilder();
arrProperties.Append(" [ ");
foreach (string item in (List<string>)i.Value)
{
arrProperties.Append(item + ", ");
}
arrProperties.Remove(arrProperties.Length - 2, 2);
arrProperties.Append(" ]");
tvItem.Items.Add(new TreeViewItem { Header = i.Key + " : " + arrProperties.ToString() });
}
}
ptvItem.Items.Add(tvItem);
ptvItem = tvItem;
}
trvQueryPlan.Items.Add(ptvItem);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question