Telerik Tree View Check/Uncheck Parent/Child Nodes on Client End
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
While using default Telerik tree control shipped with DNN, I needed a client side function to perform following,
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
- Check all children nodes if parent node is checked
- Uncheck all children nodes if parent node is unchecked
- Check parent node when all children nodes are checked
- Uncheck parent node when any single of child node is unchecked
The standard practice to perform such an operation is by setting the OnClientNodeChecked property,
<telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="True"
OnClientNodeChecked="clientNodeChecked"></telerik:RadTreeView>
To the function handler which receives the reference to checked/unchecked node in argument. Such a function is given below,
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
function clientNodeChecked(sender, eventArgs) {
//1- Uncheck Parent Node in upward fashion
var node = eventArgs.get_node();
if (!node.get_checked()) {
while (node.get_parent().set_checked != null) {
node.get_parent().set_checked(false);
node = node.get_parent();
}
}
//2- Check Child Nodes (if any)
var childNodes = eventArgs.get_node().get_nodes();
var isChecked = eventArgs.get_node().get_checked();
UpdateAllChildren(childNodes, isChecked);
//3- If all sibling nodes are checked then check parent as well
//Get Sibling nodes first
var siblingNodes = eventArgs.get_node().get_parent().get_nodes();
var i;
var allSiblingsChecked = true;
//4- Loop through all sibling nodes and see if all of them are checked
for (i = 0; i < siblingNodes.get_count(); i++) {
isChecked = siblingNodes.getNode(i).get_checked();
if (!isChecked) {
allSiblingsChecked = false;
break;
}
}
if (allSiblingsChecked) {
//Check parent node now
eventArgs.get_node().get_parent().set_checked(true);
}
}
function UpdateAllChildren(nodes, checked) {
var i;
for (i = 0; i < nodes.get_count(); i++) {
if (checked) {
nodes.getNode(i).check();
}
else {
nodes.getNode(i).set_checked(false);
}
if (nodes.getNode(i).get_nodes().get_count() > 0) {
UpdateAllChildren(nodes.getNode(i).get_nodes(), checked);
}
}
}
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
Ref: http://www.telerik.com/help/aspnet-ajax/tree_checkboxesallchildnodes.html
Iconoclast : A breaker of images
How can I convert an icon to image? Google it. Ok… I am on Google, which tool to download?
These are some of many questions I have to answer every few days so here goes another 20 minutes effort utility for two way conversions between images and icons.
Icon Editor: http://usmanahmed.info/downloads/iconoclast.zip
Icon Editor Source: http://usmanahmed.info/downloads/iconoclast_source.zip
Developed in C#, 2010 and the conversion code fragments are given below,
Icon to Image
Icon a = new Icon(iconPath);
Image im = a.ToBitmap();
im.Save(imagePath);
Image to Icon
Brush b = new SolidBrush(lblColor.ForeColor);
g.FillRectangle(b, 0, 0, width, height);
g.DrawImage(img, 0, 0, width, height);
g.Flush();
Off course it doesn’t provide state of the art implementation in terms of keeping aspect ratio or deals with image formats and is the simplest possible solution. For best results, use resolution 32 x 32 during image to icon conversion.
Note: Iconoclast in literal terms means, “A breaker of images”. Since this simple utility allows icons to image and image to icon conversions, the name r it other way round.
About Me
Usman ur Rehman Ahmedis known as a software engineer in Lahore, Pakistan. He is renowned for having an abstract understanding of vast range of technological developments such as programming languages, web development, RIA's and documental writing, and is mainly specialized in developmental analysis.
Tags
- windows phone 7 (15)
- DNN (14)
- Dot Net Nuke (13)
- .NET (5)
- c# (5)
- manifest (4)
- Application (3)
- MySql (3)
- Provider (3)
- Sql (3)
- View all 237 tags »
- Sql Server (3)
- Stored Procedure (3)
- visual sutdio (3)
- API (2)
- Data (2)
- Mango (2)
- Module (2)
- Permission (2)
- PhoneTextBlock (2)
- User Control (2)
- Windows (2)
- config (2)
- console (2)
- developer (2)
- dot net (2)
- emulator (2)
- enumeration (2)
- expression blend (2)
- extension (2)
- loop (2)
- network (2)
- phone 7 (2)
- tools (2)
- transparent (2)
- .ascx (1)
- 3g (1)
- 5.6.2 (1)
- 7.1 (1)
- 7.5 (1)
- AJAX (1)
- Activity (1)
- App.xaml (1)
- AppManifest (1)
- ApplicationIcon (1)
- Arabic (1)
- Background.png (1)
- BuildAction (1)
- Connector (1)
- Control Panel (1)
- Core Version (1)
- Data-tier (1)
- DataBound (1)
- Database (1)
- Dependency (1)
- DeviceNetworkInterface (1)
- Directory (1)
- Dynamic (1)
- EVDO (1)
- Encryption (1)
- File (1)
- FileSystemWatcher (1)
- Filter (1)
- Foreign Key (1)
- Function (1)
- GUID (1)
- GetSiteLog (1)
- Hash (1)
- Host Settings (1)
- IIS6 (1)
- IIS7 (1)
- Integrated Mode (1)
- Internet Explorer (1)
- IsolatedStorage (1)
- Java (1)
- Koder (1)
- Linq (1)
- Lists (1)
- Log (1)
- Marketplace (1)
- Membership (1)
- Microsoft (1)
- NavigationCacheMode (1)
- NavigationContext (1)
- NavigationService (1)
- Notify (1)
- OnClientNodeChecked (1)
- PTCL (1)
- Panaroma (1)
- Password (1)
- Properties (1)
- Query String (1)
- ResXResourceReader (1)
- ResolveHostNameAsync (1)
- Right to Left (1)
- SDK (1)
- SEO (1)
- SendKeys (1)
- SendWait (1)
- SharpPCap (1)
- Stream (1)