Place data from the datagridview control to the Treeview control [reprint]

Source: Internet
Author: User
How to import data from the datagridview control to the Treeview control and enable the control in the mousedown event of the datagridview.
Then, you can receive and place data in the dragenter of the Treeview.
Finally, the result is processed in dragdrop of the Treeview.
Note: Set the allowdrop attribute of Treeview to true.
: 1 private void maid (Object sender, mouseeventargs E)
2 {
3 if (E. Button = mousebuttons. Right)
4 {
5 datagridview. hittestinfo info = maid (E. X, E. y );
6
7 if (info. rowindex> = 0)
8 {
9 datagridviewrow DR = (datagridviewrow)
10 datagridview1.rows [info. rowindex];
11 if (Dr! = NULL)
12 datagridview1.dodragdrop (DR, dragdropeffects. copy );
13}
14}
15}
16
17 private void treeviewincludragenter (Object sender, drageventargs E)
18 {
19 E. effect = dragdropeffects. copy;
20}
21
22 private void treeviewincludragdrop (Object sender, drageventargs E)
23 {
24 if (E. Data. getdatapresent (typeof (datagridviewrow )))
25 {
26 point P = treeview1.pointtoclient (new point (E. X, E. y ));
27 treeviewhittestinfo Index = treeview1.hittest (P );
28
29 If (index. node! = NULL)
30 {
31
32 datagridviewrow DRV = (datagridviewrow) E. Data. getdata (typeof (datagridviewrow ));
33 index. node. Text = "Drop:" + DRV. cells [0]. tostring ();
34
35}
36}
37} Implementation Method: In the mousedown event of the datagridview.
Then, you can receive and place data in the dragenter of the Treeview.
Finally, the result is processed in dragdrop of the Treeview.
Note: Set the allowdrop attribute of Treeview to true.
: 1 private void maid (Object sender, mouseeventargs E)
2 {
3 if (E. Button = mousebuttons. Right)
4 {
5 datagridview. hittestinfo info = maid (E. X, E. y );
6
7 if (info. rowindex> = 0)
8 {
9 datagridviewrow DR = (datagridviewrow)
10 datagridview1.rows [info. rowindex];
11 if (Dr! = NULL)
12 datagridview1.dodragdrop (DR, dragdropeffects. copy );
13}
14}
15}
16
17 private void treeviewincludragenter (Object sender, drageventargs E)
18 {
19 E. effect = dragdropeffects. copy;
20}
21
22 private void treeviewincludragdrop (Object sender, drageventargs E)
23 {
24 if (E. Data. getdatapresent (typeof (datagridviewrow )))
25 {
26 point P = treeview1.pointtoclient (new point (E. X, E. y ));
27 treeviewhittestinfo Index = treeview1.hittest (P );
28
29 If (index. node! = NULL)
30 {
31
32 datagridviewrow DRV = (datagridviewrow) E. Data. getdata (typeof (datagridviewrow ));
33 index. node. Text = "Drop:" + DRV. cells [0]. tostring ();
34
35}
36}
37}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.