从treeview父节点中删除链接

时间:2010-07-27 06:52:53

标签: c# treeview

有没有办法可以保留父节点的文本但删除链接? treeview父节点仅用作标题,不用导航。任何帮助都会很棒。感谢。

private void BindNodes(string PtID)  
{  
    if (PtID != "")  
    {  
        int PatientID = Convert.ToInt32(PtID);  
        DBConnection dbObj = new DBConnection();  
        if (Session["Activepatient"] != null)  
        {  
            string[] SubChild = new string[4];  
            SubChild[0] = "Demographics";  
            SubChild[1] = "Medication Reviews";  
            SubChild[2] = "Drug Testing & Monitoring";  
            SubChild[3] = "Other Program";
            TreeNode oTrParent = new TreeNode();  
            //trv_patient.ParentNodeStyle = "None";
            //oTrParent.SelectAction.Style.Add("display", "none");
            TreeNode oTrSubChild1;
            TreeNode oTrSubChild;
            for (int i = 0; i < 4; i++)
            {
                oTrSubChild1 = new TreeNode();
                oTrSubChild1.Text = SubChild[i];
                if (i == 1)
                {
                    PatientInfoCollection patientCollection = new PatientInfoCollection();
                    patientCollection = dbObj.GetMedicationReviews(PatientID);
                    foreach (PatientInfo au in patientCollection)
                    {
                        oTrSubChild = new TreeNode();
                        PatientInfo Patient = new PatientInfo();
                        oTrSubChild.Text = au.DateRcvd.Value.ToString("MM-dd-yyyy")
                        oTrSubChild.Target = au.ReviewId.ToString();
                        oTrSubChild1.ChildNodes.Add(oTrSubChild);
                    }
                    oTrSubChild = new TreeNode();
                    oTrSubChild.Text = "Add Medication Review";
                    oTrSubChild.Target = "New";
                    oTrSubChild1.ChildNodes.Add(oTrSubChild);
                }
                trv_patient.Nodes.Add(oTrSubChild1);
            }
        }
    }
}

4 个答案:

答案 0 :(得分:4)

如果temp是这样的节点,其文本要是纯文本而不是链接,那么请使用下面的代码。

TreeNode temp = new TreeNode("text");
temp.SelectAction = TreeNodeSelectAction.None;
treeView1.Nodes.Add(temp);

答案 1 :(得分:2)

这就是你要找的东西。您必须将父节点SelectAction的{​​{1}}设置为TreeNode。我甚至还展示了如何与孩子一起做这件事。

ASP.NET

TreeNodeSelectAction.None

C#

<asp:TreeView 
  ID="MyTreeView" 
  ShowCheckBoxes="Parent,Leaf,All" 
  runat="server" 
  ShowLines="true" 
  ShowExpandCollapse="true">
</asp:TreeView>

答案 2 :(得分:0)

我不确定我是否理解你想要的东西。假设它是WinForms并且您只想禁用在TreeView中选择根节点的功能,您只需处理BeforeSelect的{​​{1}}事件,然后使用以下代码:

TreeView

答案 3 :(得分:0)

TreeNode root = new TreeNode(&#34; Root&#34;); root.SelectAction = TreeNodeSelectAction.None;

相关问题