Tree view checkboxes checking progmatically
Posted: Wed Oct 03, 2018 5:22 pm
I am trying to find and check treeview nodes check boxes in a winforms 4.5 Treeview. The nodes are picked up from a variable with each main node on a separate line, but subnodes seperated by \
e.g
Node1
Node2\subnode 3
given a tree like this and wanting to select the two items node 1 and subnode 3
root
|
Node 1
|
Node 2
|
subnode 1
|
subnode 2
|
subnode3
Now check moves to the middle of the item not the checkbox and the click is also too far to the right. I assume therefore I am selecting incorrectly has anyone a better way of doing this. I cannot put the nodes in the repository as they change dependent of data read in and thus have to be read from the spreadsheet of variables.
e.g
Node1
Node2\subnode 3
given a tree like this and wanting to select the two items node 1 and subnode 3
root
|
Node 1
|
Node 2
|
subnode 1
|
subnode 2
|
subnode3
public void SelectTreeItems(string Nodes, Adapter TreeView) { List <string> treeNodes = FileHandlers.SplitToLines(Nodes).ToList(); for (int i=0; i< treeNodes.Count; i++) { List <string> elements = treeNodes.Split('\\').ToList (); StringBuilder nodeText = new StringBuilder ("container[@controlname='tableLayoutPanel1']/tree[@controlname='treeViewAttachments']/"); foreach (string element in elements) { nodeText.Append ("/checkbox[@accessiblename='"); nodeText.Append(element); nodeText.Append("']"); } Report.Log(ReportLevel.Info, "Find", "Finding"+nodeText.ToString()); RxPath rp = new RxPath (nodeText.ToString()); var _attachmentInfo = new RepoItemInfo(repo.FormOutlookAttachments, treeNodes , rp, 30000, null, Guid.NewGuid ().ToString ()); Ranorex.CheckBox checkControl = (_attachmentInfo.CreateAdapter<Ranorex.CheckBox>(true) as Ranorex.CheckBox); checkControl.Click(Location.CenterLeft); //checkControl.Check (); } }
Now check moves to the middle of the item not the checkbox and the click is also too far to the right. I assume therefore I am selecting incorrectly has anyone a better way of doing this. I cannot put the nodes in the repository as they change dependent of data read in and thus have to be read from the spreadsheet of variables.