我正在使用具有此结构的树视图
我必须为表示数据类型(int,char等等)的每个SUB-SUBCHILD添加一个图像,但它以奇怪的方式工作......
image1是“char”图像而不是“int” image2是“char”图像 image3是“双”图像而不是“char” image4是默认(索引0)图像而不是“double”
最后一个SUB-SUBCHILD总是与预期不同!
在调试模式下,imagelist索引值是我期望看到的,但在树视图中没有。
为什么?
这是我的代码:
private void createTree(string[,] strArrLF3) //strArrLF3 matrix of n ROWS and 11 COLS
{
int counter = 0;
Int32 arrayLen = 0;
arrayLen = (strArrLF3.Length) / 11;
trvSimulations.ImageList = imgListRes; //trvSimulation is the name of treeview
TreeNode ParentNode = new TreeNode();
ParentNode.Text = "Root";
ParentNode.ForeColor = Color.Black;
ParentNode.BackColor = Color.White;
ParentNode.ImageIndex = 0;
ParentNode.SelectedImageIndex = 0;
trvSimulations.Nodes.Add(ParentNode); //Root node
TreeNode trvChild_ATSM0 = new TreeNode();
trvChild_ATSM0.Text = "CHILD1";
trvChild_ATSM0.ForeColor = Color.Black;
trvChild_ATSM0.BackColor = Color.White;
trvChild_ATSM0.ImageIndex = 1;
trvChild_ATSM0.SelectedImageIndex = 1;
ParentNode.Nodes.Add(trvChild_ATSM0); //CHILD1 node (child of Root node)
TreeNode chdIN_ATSM0 = new TreeNode();
chdIN_ATSM0.Text = "Input Signals";
chdIN_ATSM0.ForeColor = Color.Black;
chdIN_ATSM0.BackColor = Color.White;
chdIN_ATSM0.ImageIndex = 3;
chdIN_ATSM0.SelectedImageIndex = 3;
trvChild_ATSM0.Nodes.Add(chdIN_ATSM0); //Input node (child of CHILD1)
TreeNode chdOUT_ATSM0 = new TreeNode();
chdOUT_ATSM0.Text = "Output Signals";
chdOUT_ATSM0.ForeColor = Color.Black;
chdOUT_ATSM0.BackColor = Color.White;
chdOUT_ATSM0.ImageIndex = 2;
chdOUT_ATSM0.SelectedImageIndex = 2;
trvChild_ATSM0.Nodes.Add(chdOUT_ATSM0); //Output node (child of CHILD1)
TreeNode sub_chdIN_ATSM0 = new TreeNode(), sub_chdOUT_ATSM0 = new TreeNode();
counter = 0;
int imagePos = 0;
for (counter = 0; counter < arrayLen; counter++)
{
string signal = strArrLF3[counter, 9]; //matrix column containing a string ("int", "char", "long", "double")
imagePos = imageSigType(signal); //function containing a SWITCH/CASE that return an integer value (index of imagelist)
if (strArrLF3[counter, 0] == "CHILD1")
{
if (strArrLF3[counter, 8] == "I")
{
sub_chdIN_ATSM0.ImageIndex = imagePos;
sub_chdIN_ATSM0.SelectedImageIndex = imagePos;
sub_chdIN_ATSM0 = chdIN_ATSM0.Nodes.Add(strArrLF3[counter, 1]);
}
else if (strArrLF3[counter, 8] == "O")
{
sub_chdOUT_ATSM0.ImageIndex = imagePos;
sub_chdOUT_ATSM0.SelectedImageIndex = imagePos;
sub_chdOUT_ATSM0 = chdOUT_ATSM0.Nodes.Add(strArrLF3[counter, 1]);
}
}
}
}
由于