Hello,
I have an UltraTree which has a view style of OutlookExpress.
I dynamically create the tree and add the nodes to the first UltraTreeNodeColumn I have. That way I have the tree positioned in the left most column of the Grid. This column is defined as follows:
UltraTreeNodeColumn TreeCol = new UltraTreeNodeColumn(); TreeCol = new UltraTreeNodeColumn(); TreeCol.Key = "Tree"; TreeCol.Text = "Tree"; TreeCol.MaxLength = 100; TreeCol.NullText = "NULL"; TreeCol.AutoSizeMode = Infragistics.Win.UltraWinTree.ColumnAutoSizeMode.VisibleNodes; TreeCol.AllowSorting = DefaultableBoolean.True; TreeCol.DataType = typeof(string); ultratree1.ColumnSettings.RootColumnSet.Columns.Add(TreeCol);
As can be seen, the type of data this column receives is a string, i.e. the node's name.
My problem is that I am having trouble displaying an image / icon on the left hand side of the node's name. This feature was possible when the UltraTree was defined as standard for example and then the code below worked:
node.Override.NodeAppearance.Image = _ImageList.Images["img"];
Now that my tree has an OutlookExpress look-and-feel the icons I initially defined do not appear any longer even though the code executes correctly.
What's the best way to add icons to the nodes in the UltraTreeNodeColum?
Thanks.
If you are using OutlookExpress or grid style, then you need to put the image into a cell, rather than on the node. So you could either use the Appearance on the cell of the column you are referring to here or add another column and use that column to display just the image.
Hi Mike,
Can you please give me some sample code to add a image column to the UltraTree when the ViewStyle is OutlookExpress.
Thanks & Regards
Srihari Reddy .R
Assuming you are going with the unbound column solution, you add the column in response to the ColumnSetGenerated event, and assign the actual value for each node in response to the InitializeDataNode event:
private void ultraTree1_ColumnSetGenerated(object sender, ColumnSetGeneratedEventArgs e){ TreeColumnsCollection columns = e.ColumnSet.Columns; UltraTreeNodeColumn imageColumn = columns.Add( "Image" ); imageColumn.DataType = typeof(System.Drawing.Image);}
private void ultraTree1_InitializeDataNode(object sender, InitializeDataNodeEventArgs e){ if ( e.Reinitialize == false ) { Image image = Image.FromFile( @"C:\Wherever\whatever.bmp"); e.Node.SetCellValue( e.Node.DataColumnSetResolved.Columns["Image"], image ); }}
Finally I found out how to do it exactly as I want it to look like. It was just not easy to find the right attribute to set :
ultraTree.Nodes[parentKey].Cells[key].Appearance.Image = image;
Now I have an icon on the left ot each node of the tree in my OutlookExpress view.
Just to clarify, that will display the image inside that cell, and if that column is moved, the cell will move along with it.
Thank you, that's exactly the behaviour I was looking for: an image to the left of each node label in the tree column. Of course if I move the tree, the icons have to move with the labels !
I think that answers the original question of this thread : "displaying an image / icon on the left hand side of the node's name".
Juscher said:Thank you, that's exactly the behaviour I was looking for: an image to the left of each node label in the tree column. Of course if I move the tree, the icons have to move with the labels !
My point here is that, unlike with the standard ViewStyle where the NodeAppearance.Image is always displayed between the expansion indicator and the node's text, in this scenario the image is contained within the cell, and if you move the column (not talking about moving the control), the image moves along with it, and won't be the leftmost element anymore.