I am using a BindingList object as my datasource and I would like to use an image list to display images in my treeview. I looked for an ItemDataBound event or something similiar, but I did not see it. I tried to use the DrawNode Event but I would get an error saying that the ImageIndex Property could not be updated because the treeview was in lock mode or something along those lines. How do you suggest adding images when databinding?
Thanks.
Thanks.
8 Answers, 1 is accepted
0
Hello Seth,
Best wishes,
Victor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
When you assign a data source to RadTreeView, its nodes collection fires CollectionChanged event. You can subscribe to this event and assign images to the nodes as needed. In order to determine whether the treeview fires CollectionChanged upon data binding you can create a boolean flag. The example below demonstrates this:
radTreeView1.Nodes.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(Nodes_CollectionChanged); |
myFlag = true; |
radTreeView1.DataSource = lst; |
myFlag = false; |
void Nodes_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e) |
{ |
if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add) |
{ |
if (myFlag) |
{ |
// Assign images here. |
((RadTreeNode)e.NewItems[0]).Image = null; |
} |
} |
} |
Thank you for pointing out this omission in RadTreeView. We will add an ItemDataBound event in Q3 2009.
Please note that only customers receive free support. Please renew your subscription.
Please note that only customers receive free support. Please renew your subscription.
Best wishes,
Victor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matthew Link
Top achievements
Rank 1
answered on 10 Sep 2010, 03:10 PM
Is this still the appropriate method to use when trying to set images while databinding? I'm using 2010 Q2 SP1 and I notice that there is still not an ItemDataBound event.
Thanks!
Matthew
Thanks!
Matthew
0
Hi Matthew Link,
Thank you for contacting us.
The approach for setting images on RadTreeView nodes has been slightly changed. Please refer to the following code snippet:
All the best,
Stefan
the Telerik team
Thank you for contacting us.
void
Form1_Shown(
object
sender, EventArgs e)
{
SetImages(radTreeView1.Nodes);
}
void
SetImages(RadTreeNodeCollection NodesCollection)
{
foreach
(RadTreeNode node
in
NodesCollection)
{
if
(node.Nodes.Count == 0)
{
node.ImageIndex = 0;
node.SelectedImageIndex = 1;
node.StateImageIndex = 2;
}
else
if
(node.Nodes.Count > 0)
{
node.ImageIndex = 0;
foreach
(RadTreeNode childNode
in
node.Nodes)
{
SetImages(node.Nodes);
}
}
}
}
All the best,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hi Matthew Link,
Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out.
For more information about this release, please refer to this blog post.
Kind regards,
Stefan
the Telerik team
Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out.
For more information about this release, please refer to this blog post.
Kind regards,
Stefan
the Telerik team
0
Noah
Top achievements
Rank 1
answered on 09 May 2011, 10:48 PM
Is this still the best way to do this?
I have a RadTreeView that is dataBound to a self referencing table.
I would like to have a column in the table that corresponds to the ID field of an ImageList that i am using.
or do I still have to use recursion to loop threw all the nodes and assign there images?
I have a RadTreeView that is dataBound to a self referencing table.
I would like to have a column in the table that corresponds to the ID field of an ImageList that i am using.
or do I still have to use recursion to loop threw all the nodes and assign there images?
0
Hi Matthew,
Thank you for writing.
If you have a populated ImageList and you have a column in the data source which holds an index valid for the ImageList, you can access this column value through the DataBoundItem property of RadTreeNode. Here is an example, where I am setting the ImageIndex of a node to the value that the first column of the data row returns (it is ID and holds the index):
Stefan
the Telerik team
Thank you for writing.
If you have a populated ImageList and you have a column in the data source which holds an index valid for the ImageList, you can access this column value through the DataBoundItem property of RadTreeNode. Here is an example, where I am setting the ImageIndex of a node to the value that the first column of the data row returns (it is ID and holds the index):
void
radTreeView1_NodeFormatting(
object
sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
DataRowView dataRowView = e.Node.DataBoundItem
as
DataRowView;
e.Node.ImageIndex = Convert.ToInt32(dataRowView[0]);
}
I hope this helps.
Regards,Stefan
the Telerik team
0
Aravind
Top achievements
Rank 1
answered on 31 Dec 2012, 03:41 AM
hi
i am use radtreeview in my project,after i add a file in the radtreeview it does not show in the radtreeview,if i add parent node or child node it show ,but it add file it does not show in the treeview,if i close and open project then only it show the file ,
pls reply me how to refresh the treeview,i use update(),Endupdate(),invalid(),refersh(),treeview1_SelectedNode(Nothing,Nothing)
i am use radtreeview in my project,after i add a file in the radtreeview it does not show in the radtreeview,if i add parent node or child node it show ,but it add file it does not show in the treeview,if i close and open project then only it show the file ,
pls reply me how to refresh the treeview,i use update(),Endupdate(),invalid(),refersh(),treeview1_SelectedNode(Nothing,Nothing)
0
Hello Aravind,
Thank you for writing.
I would suggest that you open a new support thread with your inquiry, in order to avoid mixing different scenarios in the same thread. This way, it will be easier for the community to find the information needed. See p4 from this thread: http://www.telerik.com/community/forums/winforms/treeview/important-information-on-using-the-telerik-forums.aspx.
Furthermore, in the support thread you can attach a sample project where the undesired behavior can be reproduced and our support team will look into it for you.
Regards,
Stefan
the Telerik team
Thank you for writing.
I would suggest that you open a new support thread with your inquiry, in order to avoid mixing different scenarios in the same thread. This way, it will be easier for the community to find the information needed. See p4 from this thread: http://www.telerik.com/community/forums/winforms/treeview/important-information-on-using-the-telerik-forums.aspx.
Furthermore, in the support thread you can attach a sample project where the undesired behavior can be reproduced and our support team will look into it for you.
Regards,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.