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
;
}