C# WPF Treeview добавить субтомC#

Место общения программистов C#
Ответить
Anonymous
 C# WPF Treeview добавить субтом

Сообщение Anonymous »

Я хочу вставить субтом в представление дерева, к сожалению, я добавляю только корневой элемент.
Где проблема? < /p>

Код: Выделить всё

public MainWindow()
{

InitializeComponent();

DataContext = this;
HoleTreeViewDaten();
LVAnzahlInt32 = MyAktTVList.Count;

MenuItem root = new MenuItem();
MenuItem childItem1 = new MenuItem();
MenuItem childItem2 = new MenuItem();
MenuItem childItem3 = new MenuItem();

var item = new TreeViewItem();

root = new MenuItem() { Text = TreeViewErsterEintrag, ImageSource = TreeViewErsterIcon };

int ix = 0;
int i1 = 0;
while (i1 < LVAnzahlInt32)
{
if (MyAktTVList[i1].Position == "1")
{
childItem1 = new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon };
root.Items.Add(childItem1);
MyTreeView003.Items.Add(childItem1);
}

if (MyAktTVList[i1].Position == "2")
{
childItem2 = new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon };
root.Items.Add(childItem2);
var subItem = new TreeViewItem();
MyTreeView003.Items.Add(childItem2);
}

if (MyAktTVList[i1].Position == "3")
{
childItem3 = new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon };
root.Items.Add(childItem3);
var subItem = new TreeViewItem();
MyTreeView003.Items.Add(childItem3);
}

i1++;

}

}

Я обнаружил много примеров, но в созвездии с:


lin /> Текст
, к сожалению, ничего, как субтом < /li>
< /ul>
i-chage the code to: < /p>

Код: Выделить всё

                if (MyAktTVList[i1].Position == "1")
{
childItem1 = new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon };
root.Items.Add(childItem1);
}

if (MyAktTVList[i1].Position == "2")
{
childItem1.Items.Add( new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon });
}

if (MyAktTVList[i1].Position == "3")
{
childItem2.Items.Add(new MenuItem() { Text = MyAktTVList[i1].Bezeichnung, ImageSource = "Images/" + MyAktTVList[i1].MenueIcon });
childItem1.Items.Add(childItem2);
}


Теперь я становлюсь этим деревом:


Подробнее здесь: https://stackoverflow.com/questions/797 ... dd-subitem
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»