lapucca
asked on
need sample code on how to get the TreeView control to select and foucs on the node that is the parent node of the child node that I juts double clicked on the listivew control. And the TreeView con
Hi, I'm using vs2005 .net 2.0. I need some sample code for ListView_MouseDoubleClick event. I have a left pane of a treeview control and a right pane of a Listview control that list 1 level of the children nodes of the TreeView's selected node. I need some sample code to perform behvior like one sees in the Active Directory Users and Computers snap-in.
I need sample code on how to get the TreeView control to select and foucs on the node that is the parent node of the child node that I juts double clicked on the listivew control. And the TreeView control would also expand 1 level.
Thanks.
I need sample code on how to get the TreeView control to select and foucs on the node that is the parent node of the child node that I juts double clicked on the listivew control. And the TreeView control would also expand 1 level.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Mishu,
TreeNode aNode = listView.SelectedItems[0]. Tag as TreeNode;
seems to always returning null.
Thanks.
TreeNode aNode = listView.SelectedItems[0].
seems to always returning null.
Thanks.
Sorry I forgot something...
Add this line at the after select event:
listView.Items.Add(li);
Regards,
Mishu
Add this line at the after select event:
listView.Items.Add(li);
Regards,
Mishu
ASKER
Hi Mishu,
I've added the code as follow but when I double clicked on the Listview's node, nothing happens. Thanks.
private void ppTree_AfterSelect(object sender, TreeViewEventArgs e)
{
NodeDetail.Items.Clear();
foreach (TreeNode node in e.Node.Nodes)
{
ListViewItem li = new ListViewItem(node.Text);
li.Tag = (object)node;
NodeDetail.Items.Add(li);
}
............
private void NodeDetail_MouseDoubleClic k(object sender, MouseEventArgs e)
{
if (NodeDetail.SelectedItems[ 0]!=null)
{
TreeNode aNode = NodeDetail.SelectedItems[0 ].Tag as TreeNode;
if (aNode != null)
ppTree.SelectedNode = aNode;
}
}
I've added the code as follow but when I double clicked on the Listview's node, nothing happens. Thanks.
private void ppTree_AfterSelect(object sender, TreeViewEventArgs e)
{
NodeDetail.Items.Clear();
foreach (TreeNode node in e.Node.Nodes)
{
ListViewItem li = new ListViewItem(node.Text);
li.Tag = (object)node;
NodeDetail.Items.Add(li);
}
............
private void NodeDetail_MouseDoubleClic
{
if (NodeDetail.SelectedItems[
{
TreeNode aNode = NodeDetail.SelectedItems[0
if (aNode != null)
ppTree.SelectedNode = aNode;
}
}
Replace your current method with this:
private void NodeDetail_MouseDoubleClic k(object sender, MouseEventArgs e)
{
if (NodeDetail.SelectedItems[ 0]!=null)
{
TreeNode aNode = NodeDetail.SelectedItems[0 ].Tag as TreeNode;
if (aNode != null)
{
ppTree.SelectedNode = aNode;
aNode.EnsureVisible();
ppTree.Focus();
}
}
}
Hope it solves the problem.
Regards,
Mishu
private void NodeDetail_MouseDoubleClic
{
if (NodeDetail.SelectedItems[
{
TreeNode aNode = NodeDetail.SelectedItems[0
if (aNode != null)
{
ppTree.SelectedNode = aNode;
aNode.EnsureVisible();
ppTree.Focus();
}
}
}
Hope it solves the problem.
Regards,
Mishu
lapucca, did you try the sample application I posted?
//You can put in the tag property of the list view item the node reference...
private void treeView_AfterSelect(objec
{
listView.Items.Clear();
foreach (TreeNode node in e.Node.Nodes)
{
ListViewItem li = new ListViewItem(node.Text);
li.Tag = (object)node;
}
}
private void listView_DoubleClick(objec
{
if (listView.SelectedItems[0]
{
TreeNode aNode = listView.SelectedItems[0].
if (aNode != null)
tree.SelectedNode = aNode;
}
}
Hope this helps.
Regards,
Mishu