Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to get rid of the space reserved for an image in a TreeListNode

$
0
0

When the TreeList.SelectImageList or TreeList.StateImageList properties are assigned, each TreeListNode has an indent to draw these images, even if the TreeListNode.SelectImageIndex or TreeListNode.StateImageIndex properties are set to -1.

In a situation when this behavior is undesirable, it's possible to create a custom TreeList descendant, and change it by overriding the TreeListViewInfo.GetDataBoundsLocation method.

Question Comments

Added By: Daniel Parsons at: 7/7/2015 12:06:05 PM    

Corrected code as follows:
protected override void CalcStateImage(RowInfo ri)
       {
           base.CalcStateImage(ri);
           if (Size.Empty != RC.StateImageSize && -1 == ri.Node.StateImageIndex)
               ri.StateImageLocation.X -= RC.StateImageSize.Width;
       }

Added By: Jacobo Amselem at: 11/6/2017 2:41:05 AM    Fix the code sample!

I missed Daniel's comment and spent a few hours before coming to the same conclusion...  Added By: Nadezhda (DevExpress Support) at: 11/7/2017 6:45:17 AM    

Hello Jacobo,

We will update this example as soon as possible. We appreciate your patience.

Added By: waresofter at: 12/21/2017 3:03:41 AM    have you testing the version 17.2.4 ?

there has a bug, if override the CalcStateImageBounds function, the treelist's GetStateImage event will not be eraising! 


Added By: waresofter at: 12/21/2017 3:06:03 AM    
[C#]
usingDevExpress.XtraEditors;usingDevExpress.XtraTreeList;usingDevExpress.XtraTreeList.Nodes;usingDevExpress.XtraTreeList.ViewInfo;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceDevSample{publicpartialclassFrmTreeList:XtraForm{publicFrmTreeList(){InitializeComponent();this.treeList1.FocusedNodeChanged+=TreeList1_FocusedNodeChanged;List<Record>records=newList<Record>(newRecord[]{newRecord(1,"test1","i can raising focusNodeChanged event"),newRecord(2,"test2","i can raising focusNodeChanged event")});this.treeList1.DataSource=records;}privatevoidTreeList1_FocusedNodeChanged(objectsender,DevExpress.XtraTreeList.FocusedNodeChangedEventArgse){Recordrec=this.treeList1.GetDataRecordByNode(e.Node)asRecord;System.Diagnostics.Debug.WriteLine(rec.Name);}classRecord{publicintIndex{get;set;}publicstringName{get;set;}publicstringDescription{get;set;}publicRecord(){}publicRecord(intidx,stringname,stringdesc){this.Index=idx;this.Name=name;this.Description=desc;}}privatevoidbuttonEdit1_ButtonClick(objectsender,DevExpress.XtraEditors.Controls.ButtonPressedEventArgse){if(e.Button.Caption=="添加记录"){TreeListNodetln=this.treeList1.AppendNode(newobject[]{"a4","b4","c4"},-1);treeList1.FocusedNode=tln;treeList1.OptionsBehavior.Editable=true;treeList1.ShowEditor();}}privatevoidtreeList1_GetStateImage(objectsender,DevExpress.XtraTreeList.GetStateImageEventArgse){System.Diagnostics.Debug.WriteLine("treeList1_GetStateImage");Recordrec=this.treeList1.GetDataRecordByNode(e.Node)asRecord;e.NodeImageIndex=rec.Index% 2 == 0 ?-1 : 0;}}publicclassMyTreeList:TreeList{/******************************************************** * 当节点前没有图片时,去除图片占位符 * https://www.devexpress.com/Support/Center/Example/Details/E2153/how-to-get-rid-of-the-space-reserved-for-images-in-the-treelistnode-when-a-certain * * ******************************************************/publicMyTreeList():base(){}protectedoverrideTreeListViewInfoCreateViewInfo(){returnnewMyTreeListViewInfo(this);}// 当某个节点前没有图标时,不显示图标的占位空间publicclassMyTreeListViewInfo:TreeListViewInfo{publicMyTreeListViewInfo(TreeListtreeList):base(treeList){}protectedoverridevoidCalcSelectImageBounds(RowInforInfo,RectangleindentBounds){System.Diagnostics.Debug.WriteLine("CalcSelectImageBounds: "+rInfo.Node.SelectImageIndex);if(Size.Empty!=RC.SelectImageSize&&-1 ==rInfo.Node.SelectImageIndex)return;base.CalcSelectImageBounds(rInfo,indentBounds);}protectedoverridevoidCalcStateImageBounds(RowInforInfo,RectangleindentBounds){System.Diagnostics.Debug.WriteLine("CalcStateImageBounds: "+rInfo.Node.StateImageIndex);if(Size.Empty!=RC.StateImageSize&&-1 ==rInfo.Node.StateImageIndex)return;base.CalcStateImageBounds(rInfo,indentBounds);}}}}

Added By: Nadezhda (DevExpress Support) at: 12/21/2017 7:42:13 AM    Hello,

I have created a separate ticket on your behalf: The GetStateImage event does not fire when the CalcStateImageBounds method is overrided. It has been placed in our processing queue and will be answered shortly.

Viewing all articles
Browse latest Browse all 7205

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>