This is a migrated thread and some comments may be shown as answers.

Trouble unchecking treenodes with node enable/disable

4 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
MERI
Top achievements
Rank 1
MERI asked on 11 Aug 2010, 08:55 PM
My requirement is that if a parent node is checked, all the children must be checked. We like the tristate checkbox functionality. So, what we'd like is when the parent is checked, the childnodes are disabled so that they may not be unchecked. This causes a problem with expanding and collapsing, but I've seen that there is a workaround for that. My problem comes with unchecking the parent. It unchecks and then comes right back again. There is also a problem with enabling nodes again once disabled, i.e. if the node is being unchecked due to CheckChildNodes property, the NodeCheck event is not fired and it never gets enabled again.
      
              <telerik:RadTreeView ID="rtvVendor" runat="server" CheckBoxes="True"CheckChildNodes="True" 
                            Skin="Outlook" TriStateCheckBoxes="true" Width="500px"Height="400px" BorderStyle="Solid"
                            BorderColor="#4888A2" BorderWidth="1px"
                            OnNodeCheck="rtvVendor_NodeCheck"
                            ><%-- OnNodeDataBound="rtvVendor_NodeDataBound">--%>
                        </telerik:RadTreeView>

    #region TreeVendor
        private void BindToDataTable(RadTreeView treeView)
        {
            char[] separator = new char[] { ':' };
            string[] strSplitArr = rcbAssociate.SelectedValue.Split(separator);
            string FullAssocID = strSplitArr[0];
  
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SpecialistMappingConnectionString"].ConnectionString);
            SqlCommand sqlCmd = new SqlCommand("uspSpecialistMapping_LoadFOBTree3", connection);
            SqlDataAdapter adapter = new SqlDataAdapter();
            sqlCmd.CommandType = CommandType.StoredProcedure;
  
            sqlCmd.Parameters.AddWithValue("@FullAssocID", FullAssocID);
            sqlCmd.Parameters.AddWithValue("@PDiv", rcbPDiv.SelectedValue);
  
            DataTable dataTable = new DataTable();
            adapter.SelectCommand = sqlCmd;
            adapter.Fill(dataTable);
  
            //Added by RB 5/24/2010 
            RadTreeNodeBinding binding = new RadTreeNodeBinding();
            binding.CheckedField = "IsChecked";
            treeView.DataBindings.Add(binding);
  
            binding = new RadTreeNodeBinding();
            binding.ExpandedField = "IsChecked";
            treeView.DataBindings.Add(binding);
  
            treeView.DataTextField = "FOBName";
            treeView.DataFieldID = "FOBID";
            treeView.DataValueField = "FOBID";
            treeView.DataFieldParentID = "ParentID";
            treeView.DataSource = dataTable;
            treeView.DataBind();
        }
  
  
    #endregion
  
  
    #region SaveValues
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!rcbPDiv.SelectedValue.Equals("") && !rcbAssociate.SelectedValue.Equals(""))
            {
                char[] separator = new char[] { ':' };
                string[] strSplitArr = rcbAssociate.SelectedValue.Split(separator);
                string FullAssocID = strSplitArr[0];
  
                //Delete old cheched Vendors.
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SpecialistMappingConnectionString"].ConnectionString))
                {
                    SqlCommand sqlCmd = new SqlCommand("uspSpecialistMapping_DeleteVendor", connection);
  
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.AddWithValue("@FullAssocID", FullAssocID);
                    sqlCmd.Parameters.AddWithValue("@PDiv", rcbPDiv.SelectedValue);
                    try
                    {
                        connection.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqlEx)
                    {
                        throw;
                    }
                }
  
                ShowCheckedNodes(rtvVendor, nodesClientside, FullAssocID);
  
            }
        }
  
        private void ShowCheckedNodes(RadTreeView treeView, Label label, string FullAssocID)
        {
            string message = string.Empty;
            int count = 0;
            IList<RadTreeNode> nodeCollection = treeView.CheckedNodes;
            foreach (RadTreeNode node in nodeCollection)
            {
                if (node.CheckState.ToString().Equals("Checked"))
                {
                    string tmp = node.Value;
                    if (tmp.IndexOf("3", 0, 1) != -1)
                    {
                        string strDeptID = tmp.Substring(1, 4);
                        string strVendorID = tmp.Substring(5, 4);
  
                        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SpecialistMappingConnectionString"].ConnectionString))
                        {
                            SqlCommand sqlCmd = new SqlCommand("uspSpecialistMapping_InsertVendor", connection);
  
                            sqlCmd.CommandType = CommandType.StoredProcedure;
                            sqlCmd.Parameters.AddWithValue("@FullAssocID", FullAssocID);
                            sqlCmd.Parameters.AddWithValue("@Dept", strDeptID);
                            sqlCmd.Parameters.AddWithValue("@Vendor", strVendorID);
                            try
                            {
                                connection.Open();
                                count += sqlCmd.ExecuteNonQuery();
                            }
                            catch (SqlException sqlEx)
                            {
                                throw;
                            }
                        }
  
                        message += node.Value + "[" + node.FullPath + "]" + "<br/>";
                    }
                }
            }
            if (count > 0)
            {
                string script = "alert('Changes saved successfully!')";
                RadScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), script, true);
            }
        }
    #endregion
  
      
    protected void rtvVendor_NodeCheck(object sender, RadTreeNodeEventArgs e)
    {
        rtvVendor.TriStateCheckBoxes = false;
  
        if (e.Node.Checked)
            e.Node.CheckChildNodes();
        else
            e.Node.UncheckChildNodes();
        for (int i = 0; i < e.Node.Nodes.Count; i++)
            e.Node.Nodes[i].Enabled = !e.Node.Checked;
        rtvVendor.TriStateCheckBoxes = true;
    }
  
  
  
  

4 Answers, 1 is accepted

Sort by
0
MERI
Top achievements
Rank 1
answered on 12 Aug 2010, 04:11 PM
I figured this out already. Had to turn CheckChildNodes off and create my own recursive calls to check and disable children.
0
Nikolay Tsenkov
Telerik team
answered on 13 Aug 2010, 12:59 PM
Hi MERI,

Glad to see that you managed to solve the problem on your own!
If you are having any further hard time with our controls, please contact with us again!


Regards,
Nikolay Tsenkov
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
MERI
Top achievements
Rank 1
answered on 16 Aug 2010, 06:04 PM
I am still having issues with this treeview control. One of the issues is speed. It is incredibly slow in IE, but runs very fast in Chrome. I know this is mostly due to Chrome's javascript engine. But it's unbearably slow and not acceptable. I'm hoping there is something that can be done without rewriting.

The other thing is the NodeCheck event. When I check a node that is not checked, I look at the e.Node.Checked property and it says true. Great. When I uncheck it, it tells me true again. Not so great.

Any help you could provide would be greatly appreciated.
0
Nikolay Tsenkov
Telerik team
answered on 19 Aug 2010, 09:04 AM
Hello MERI,

Could you, please open a support ticket and provide me with a sample project reproducing:
  1. the speed problems you experience in IE;
  2. the strange behavior on checking/unchecking a node.

This way I can probably suggest some optimizations regarding the performance in IE and resolve the problem with NodeCheck with some debugging.

Hope that soon we will resolve the problems you experience!


Regards,
Nikolay Tsenkov
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
Tags
TreeView
Asked by
MERI
Top achievements
Rank 1
Answers by
MERI
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Share this question
or