7 Answers, 1 is accepted
Thank you for writing.
According to the provided brief description, I suppose that you are trying to populate RadTreeView with large data coming from the database. For this case, it would be suitable to use the load on demand approach. Thus, data won't be loaded all at once. The following help article is quite useful on this topic: https://docs.telerik.com/devtools/winforms/treeview/data-binding/load-on-demand
If it is not the exact case, please specify in details what is the exact goal that you are trying to achieve. Thus, we would be able to think about a suitable solution and assist you further.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik
Hello
Please Guide me...
picture attach...
Thankful
Thank you for writing back.
The provided screenshot is greatly appreciated. In order to assign a specific image to RadTreeView nodes, it is suitable to use the NodeFormatting event. You can find a sample code snippet demonstrating how to populate RadTreeView with data and add the relevant image to the node:
private
void
RadForm1_Load(
object
sender, EventArgs e)
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"ParentId"
,
typeof
(
int
));
dt.Columns.Add(
"ImageIcon"
,
typeof
(
int
));
dt.Rows.Add(1,
"Item1"
, 0, 0);
dt.Rows.Add(2,
"Item2"
, 0, 0);
dt.Rows.Add(3,
"Item3"
, 2, 1);
dt.Rows.Add(4,
"Item4"
, 2, 1);
dt.Rows.Add(5,
"Item5"
, 4, 0);
this
.radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
this
.radTreeView1.DisplayMember =
"Name"
;
this
.radTreeView1.ParentMember =
"ParentId"
;
this
.radTreeView1.ChildMember =
"Id"
;
this
.radTreeView1.DataSource = dt;
}
private
void
radTreeView1_NodeFormatting(
object
sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
DataRowView rowView = e.Node.DataBoundItem
as
DataRowView;
if
(rowView!=
null
)
{
if
((
int
)rowView.Row[
"ImageIcon"
] == 0)
{
e.NodeElement.Image = Properties.Resources.check;
}
else
{
e.NodeElement.Image = Properties.Resources.remove;
}
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Thanks for your support and responsiveness,
But I can not find "NodeFormatting"
not Event NodeFormatting
vs 2012 and framework3.5
-private void radTreeView1_NodeFormatting-
Thank you for writing back.
The NodeFormatting event is at RadTreeView level. I have attached my sample project for your reference.
I hope this information helps.
Regards,
Dess
Progress Telerik
Good afternoon, you could help me or an explanation because when I resize the image it causes an overload error, example:
private void treeView_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
if ((e.Node.DataBoundItem as object).Imagen != null)
{
//With the following code if it gives an overload error
var imageNew = (Image)new Bitmap((e.Node.DataBoundItem as object).Imagen, new Size(8,8));
e.Node.Image = imageNew;
//With the following code does not give error
e.Node.Image = (e.Node.DataBoundItem as object).Imagen;
}
}
Please have in mind that the NodeFormatting event is constantly firing while you are scrolling, filtering the nodes or hovering a certain node. This event is purposed to introduce the correct style of a visual node element considering the current element's state. Creating a brand new image in the NodeFormatting event is not a suitable approach because a lot of images will be created with each firing of the event.
The possible solution that I can suggest is to create the necessary images in advance. You can store the images in an appropriate collection storing the unique identifier of the node and the respective image. Then, just use the already stored images in the NodeFormatting event.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik