Solved

Treeview problem (Very Hard)

Posted on 2003-10-29
2
247 Views
Last Modified: 2012-05-04
I have a drag and drop system from a treeview to a rich text box, which when you select and drag a node from the tree it places the tag value into the rich text box, however i want to just click on a node on the tree and click a button which will assign the value of its tag to a variable named puretext, this is a global variable which i am passing to another class file.


The code below is the drag and drop code, when you drag it assigns the tag of the selected node to PureText, however i dont want to have to drag the node into the text just click on it then press a button to load the other class and the tag value of the node will be in the global variable PureText.


Thanks.

If you need more code or clarrification just ask, please help asap



            // ------------------------ Drag and Drop System ----------------------------------------------------- //
        
        
            private void treeView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
            {
                  DoDragDrop(e.Item, DragDropEffects.Copy |  DragDropEffects.Move);
            }

   
        
            protected void richTextBox1_TextChanged (object sender, System.EventArgs e)
            {
                  if(richTextBox1.SelectedText=="")
                  {
                        menuItem_cut.Enabled=true;
                        menuItem_copy.Enabled=true;
                        menuItem_del.Enabled=true;
                  }
                  else
                  {
                        menuItem_cut.Enabled=false;
                        menuItem_copy.Enabled=false;
                        menuItem_del.Enabled=false;
                  }
            }

        
            private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)  
            {
                  if (e.Data.GetDataPresent(typeof(TreeNode)))
                        ((DragEventArgs)e).Effect = DragDropEffects.Copy;
                  else
                        ((DragEventArgs)e).Effect = DragDropEffects.None;
            }
        
        
            private void richTextBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
            {
                  TreeNode
                        MyNode=(TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                  PureText = MyNode.Tag.ToString();

                  int i;
                  String s;

                  i = richTextBox1.SelectionStart;
                  s = richTextBox1.Text.Substring(i);
                  richTextBox1.Text = richTextBox1.Text.Substring(0,i);

                  richTextBox1.Text = richTextBox1.Text + PureText;
                  richTextBox1.Text = richTextBox1.Text + s;
            }




Load method for the class i want to load when i select a node from the tree then click a button



private void edit_Click(object sender, System.EventArgs e)
            {
                  editbib latexide = new editbib();
                  latexide.ShowDialog(this);


            }
0
Comment
Question by:u1jd
2 Comments
 
LVL 2

Accepted Solution

by:
cuynen earned 230 total points
ID: 9647130
in the Click event of the button:

if( treeView1.SelectedNode != null )
     PureText = treeView1.SelectedNode.Tag;

when you click the button, the Tag value of the selected TreeNode will be copied to the PureText variable

notes:
+ variable names should start with a lowercase letter (myNode instead of MyNode, pureText instead of PureText, ...)
+ in OO there's no such thing as a global variable :)
0
 

Author Comment

by:u1jd
ID: 9648666
Thanks you for your code and useful comments, realise about the no global variables but it is very interesting about the lowercase thankyou for pointing it out.

Answer just needed

if( treeView1.SelectedNode != null )
    PureText = treeView1.SelectedNode.Tag.ToString();

but still it is brilliant , thankyou so much, points are all yours
 
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now