Introduction
In this blog, I am going to explain that how to make any single node of tree view Read-only in c#. Steps are below:
Steps:
Make two methods like as:
1. Call this method in any click event when you want make the node readonly TRUE.
In this blog, I am going to explain that how to make any single node of tree view Read-only in c#. Steps are below:
Steps:
- first time, when you click on Tree View in (windows application) then and do something whatever your requirements, then change the color of tree View node
- And whenever you’ll click on that particular node (changed node color in first step), then a message will appear “do you want change node selection”
Make two methods like as:
1. Call this method in any click event when you want make the node readonly TRUE.
void ReadOnlyNodeTrue ()
{
bool Isexist = false;
foreach (TreeNode t in MMCtv.Nodes)
{
foreach (DataGridViewRow dgvrr in dgvTreeView.Rows)
{
if (dgvrr.Cells["grBatchNo"].Value.ToString() == t.Text.Replace("BatchNo:- ", ""))
{
if (t.BackColor != System.Drawing.Color.Gray)
{
t.BackColor = System.Drawing.Color.Honeydew;
Isexist = true;
}
}
}
if (Isexist)
{
Isexist = false;
foreach (TreeNode t1 in t.Nodes)
{
foreach (DataGridViewRow dgvrr in dgvTreeView.Rows)
{
if (dgvrr.Cells["grCompMaterial"].Value.ToString() == t1.Text.Replace("MatCode:- ", ""))
{
if (dgvrr.Cells["grBatchNo"].Value.ToString() == t.Text.Replace("BatchNo:- ", ""))
{
if (t1.BackColor != System.Drawing.Color.Gray)
{
t1.BackColor = System.Drawing.Color.Honeydew;
Isexist = true;
}
}
}
}
if (Isexist)
{
foreach (TreeNode t2 in t1.Nodes)
{
if (t2.BackColor != System.Drawing.Color.Gray)
{
t2.BackColor = System.Drawing.Color.Honeydew;
Isexist = true;
}
}
}
Isexist = false;
}
}
}
TreeNode TN1 = MMCtv.SelectedNode;
TN1.BackColor = System.Drawing.Color.Honeydew;
}
2. Call this method in TreeView_NodeMouseClick when you want make the node readonly FALSE.
2. Call this method in TreeView_NodeMouseClick when you want make the node readonly FALSE.
void ReadOnlyNodeFalse ()
{
bool Isexist = false;
foreach (TreeNode t in MMCtv.Nodes)
{
foreach (DataGridViewRow dgvrr in dgvTreeView.Rows)
{
if (dgvrr.Cells["grBatchNo"].Value.ToString() == t.Text.Replace("BatchNo:- ", ""))
{
if (t.BackColor != System.Drawing.Color.Gray)
{
t.BackColor = System.Drawing.Color.Empty;
Isexist = true;
}
}
}
if (Isexist)
{
Isexist = false;
foreach (TreeNode t1 in t.Nodes)
{
foreach (DataGridViewRow dgvrr in dgvTreeView.Rows)
{
if (dgvrr.Cells["grCompMaterial"].Value.ToString() == t1.Text.Replace("MatCode:- ", ""))
{
if (dgvrr.Cells["grBatchNo"].Value.ToString() == t.Text.Replace("BatchNo:- ", ""))
{
if (t1.BackColor != System.Drawing.Color.Gray)
{
t1.BackColor = System.Drawing.Color.Empty;
Isexist = true;
}
}
}
}
if (Isexist)
{
foreach (TreeNode t2 in t1.Nodes)
{
if (t2.BackColor != System.Drawing.Color.Gray)
{
t2.BackColor = System.Drawing.Color.Empty;
Isexist = true;
}
}
}
Isexist = false;
}
}
}
TreeNode TN1 = MMCtv.SelectedNode;
TN1.BackColor = System.Drawing.Color.Empty;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.