2010-07-27 8 views
1

Y a-t-il un moyen de conserver le texte d'un nœud parent mais de supprimer le lien? Le nœud parent treeview est utilisé comme un en-tête, pas de navigation. Toute aide est la bienvenue. Merci.Supprimer le lien du nœud parent 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); 
      } 
     } 
    } 
} 
+0

Utilisez-vous WPF, Windows Forms ou ASP.NET? –

+0

J'utilise ASP.net avec C# –

Répondre

0

Je ne sais pas si je comprends ce que vous voulez. En supposant que c'est WinForms et que vous voulez juste désactiver la possibilité de sélectionner le nœud racine dans un TreeView vous pouvez simplement gérer l'événement BeforeSelect du TreeView et ensuite le code suivant:

if (e.Node.Parent == null) 
    e.Cancel = true; 
+0

Salut ho1, Merci pour votre réponse. Il n'y a aucun événement appelé "BeforeSelect" pour treeview. Je n'utilise pas de formulaires Windows. Quel événement doit être déclenché pour rendre le nœud parent non-cliquable. –

4

si la température est tel noeud dont le texte que vous voulez être en texte clair et ne pas lier, puis utilisez le code ci-dessous.

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

Voici ce que vous cherchez. Vous devez définir le SelectAction du nœud parent TreeNode sur TreeNodeSelectAction.None. Je montre même comment le faire avec l'enfant aussi.

ASP.NET

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

C#

//Make A Parent Node 
var Parent = new TreeNode(); 
Parent.Text = "Parent 1"; 

// Make the parent nodes not be hyperlinks but plain text 
Parent.SelectAction = TreeNodeSelectAction.None; 

//You can do the same with a child node like so 
var Child = new TreeNode(); 
Child.Text = "Child 1"; 

// Make the child nodes not be hyperlinks but plain text 
Child.SelectAction = TreeNodeSelectAction.None; 

//Add the child node to the parent node 
Parent.ChildNodes.Add(Child); 

//Finally add the parent node with children to the treeview 
MyTreeView.Nodes.Add(Parent); 
0

TreeNode racine = new TreeNode ("Root"); root.SelectAction = TreeNodeSelectAction.None;

Questions connexes