Reputation: 3618
I am using XtraTreeList.TreeList to display hierarchical data. Data are stored in my custom business objects that implement DevExpress.XtraTreeList.TreeList.IVirtualTreeListData.
While data for column "Name" are displayed normally, retirieved by the following code:
public void VirtualTreeGetCellValue(DevExpress.XtraTreeList.VirtualTreeGetCellValueInfo info)
{
if (info.Column.FieldName == "Name")
info.CellData = root.providers[provGroup.Key];
if (info.Column.FieldName == "ImageIndex")
info.CellData = imageIndex;
}
I have met with difficulties in providing appropriate image index for nodes.
To put it simply, I have no idea how to provide it. I have tried setting ImageIndexFieldName in TreeList to "ImageIndex" and handling CustomDrawNodeImages event like this:
void BoundTree_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
{
e.StateImageIndex = e.StateImageIndex = (int)(e.Node.GetValue("ImageIndex")??-1);
e.Handled = false;
}
however this doesn't produce any results.
What I would like to do is retrieve my object implementing IVirtualTreeListData that corresponds to a node, but how can that be done? In documentation it is recommended to use Node.GetValue(column) to retrieve data from node, but when it is executed, IVirtualTreeListData.VirtualTreeGetCellValue is simply not called. It seems that nodes are filled once with data corresponding to columns and then business object is used no more (well, maybe data are also set, but not in my case).
I will be grateful for any insight.
Upvotes: 2
Views: 5769
Reputation: 11277
If you have the Node
you can get the underlying DataSource by using treeControl.GetDataRecordByNode(e.Node)
In you example it would look like this:
private void BoundTree_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
{
var myType = (MyType)BoundTree.GetDataRecordByNode(e.Node);
e.StateImageIndex = myType.ImageIndex ?? -1
}
Upvotes: 4