我正在尝试创建一个 TreeView,其中树中的每个元素并排包含一个 CheckBox 和一个 ComboBox。我能够在 TreeView 中生成 ComboBoxes 并尝试使用另一个 TreeView 但这仍然不能产生我想要的输出(我希望 CheckBox 和 ComboBox 并排出现,而不是像我一样在另一个下方出现在下面的代码中管理)有没有办法可以实现这一点?下面是我现在使用的代码,非常简单。我只是将项目添加到 TreeView,有没有办法可以在 TreeView 中并排放置两个项目?
TreeViewItem foo = new TreeViewItem();
foo.Header = groupName.Text;
treeView1.Items.Add(foo);
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "Text files (*.txt)|*.txt";
dlg.FilterIndex = 0;
dlg.Multiselect = true;
dlg.RestoreDirectory = true;
dlg.Title = "Read .txt Log File";
if (dlg.ShowDialog() == true)
{
newList = new DynoFileList(groupName.Text);
foreach (String file in dlg.FileNames)
{
TreeViewItem foo2 = new TreeViewItem();
DynoFile testing = new DynoFile(file,groupName.Text); // Creating a new Dyno run file
CheckBox test = new CheckBox();
ComboBox ColorSelect = new ComboBox();
test.Click += new RoutedEventHandler(BoxClicked);
test.Content = testing.getName();
foo.Items.Add(test);
foo.Items.Add(foo2); // This does not quite produce the output that I desire, I was the items to be side by side, not cascaded in any way. The second TreeView is not absolutely necessary
foo2.Items.Add(ColorSelect);// This does not quite produce the output I want
newList.addRun(testing);
allBoxes.Add(test);
}
}