Treeview/listfview item selection
-
Using C# in a winform, I'm creating a file backup program that uses a treeview/listview pair, just like Windows Explorer, only exception is that all entries have checkboxes for selection... you make your selections and then save a backup file (in XML) containing a record of all dirs/files for that job. Works fine. In order to edit a saved job, the treeview/listview pair must be "re-hydrated", so that all selections for a given job are restored and the user can view and make changes. I know you can programmatically check/uncheck items, but I'd like to make the selections by sending mouse click messages, just as if I were making the selections for the first time with a mouse... can't use the "node.Check = true" method because it conflicts with my job creation logic. Is it possible to send mouse click messages programmatically...??? How is it done...? thanks very much.
-
Using C# in a winform, I'm creating a file backup program that uses a treeview/listview pair, just like Windows Explorer, only exception is that all entries have checkboxes for selection... you make your selections and then save a backup file (in XML) containing a record of all dirs/files for that job. Works fine. In order to edit a saved job, the treeview/listview pair must be "re-hydrated", so that all selections for a given job are restored and the user can view and make changes. I know you can programmatically check/uncheck items, but I'd like to make the selections by sending mouse click messages, just as if I were making the selections for the first time with a mouse... can't use the "node.Check = true" method because it conflicts with my job creation logic. Is it possible to send mouse click messages programmatically...??? How is it done...? thanks very much.
you can Invoke the tree's onmouseclick event with that when you fill the tree event object fill the node you want so as if it clicks on that item. Paresh;)
-
you can Invoke the tree's onmouseclick event with that when you fill the tree event object fill the node you want so as if it clicks on that item. Paresh;)
-
thanks for the reply... can you give me more info or an example of how I can send a mouseclick message to the treeview entry...??? thanks...
Ok Here is the code ;) what I tried !!! you can compile and run under shell by > csc Form1.cs > Form1 you can derive the TreeView Class and make protected method callable via making public and calling protected method. Hope this helps or gives hints to your stuff !!! ---------------------------- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WinTreeHandle { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private WinTreeHandle.Form1.MyTree treeView1; class MyTree : TreeView { public void OnMyAfterCheck(TreeViewEventArgs e) { e.Node.Checked = true; this.OnAfterCheck(e); } } private System.Windows.Forms.Button buttonClick; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; bool bLoading = true; public Form1() { bLoading = true; // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // bLoading = false; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.treeView1 = new WinTreeHandle.Form1.MyTree(); this.buttonClick = new System.Windows.Forms.Button(); this.SuspendLayout(); // // treeView1 // this.treeView1.CheckBoxes = true; this.treeView1.ImageIndex = -1; this.treeView1.Location = new System.Drawing.Point(16, 24); this.treeView1.Name = "treeView1"; this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { new System.Windows.Forms.TreeNode("Node0"), new System.Windows.Forms.TreeNode("Node1"), new System.Windows.Forms.TreeNode("Node2"), new System.Windows.Forms.TreeNode("Node3"), new System.Windows.Forms.TreeNode("Node4")});