惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
爱范儿
爱范儿
Jina AI
Jina AI
博客园 - Franky
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
M
MIT News - Artificial intelligence
aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
腾讯CDC
博客园_首页
月光博客
月光博客
有赞技术团队
有赞技术团队
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog

博客园 - huadust

msdn 网络编程 委托用法 注册表操作 DateTime各种用法 [转]将dll汇入exe 用DataTable构建树 Lock Review String Review Class Review DataTable opertion 2009_01_15_星期三 2009_01_02_星期五 2008_12_31_星期三 2008_12_24_星期三 2008_12_20_星期六 2008_12_17_星期三 2008_12_06_星期六 2008_12_04_星期四
Drag DataGridView Data To TreeView
huadust · 2009-07-17 · via 博客园 - huadust

1. Define below events, and setting TreeView property AllowDrop = True

//private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
//{
//    ataGridView1.DoDragDrop(e.RowIndex, DragDropEffects.Copy);
//}

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
    dataGridView1.DoDragDrop(dataGridView1.SelectedRows, DragDropEffects.Copy);
}
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
    
if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
    {
        DataGridViewSelectedRowCollection selected 
= (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));foreach (DataGridViewRow row in selected)
        {
            
string key = row.Cells["Index"].Value.ToString();if (m_treeTable.Rows.Contains(key) == false)
            {
                DataRow dr 
= m_treeTable.NewRow();
                dr[
"Index"= row.Cells["Index"].Value.ToString();
                dr[
"Name"= row.Cells["Name"].Value.ToString();
                dr[
"Father"= row.Cells["Father"].Value.ToString();
                m_treeTable.Rows.Add(dr);
                AddTreeNode(dr);
            }
        }
    }
    
this.treeView1.SelectedNode.BackColor = Color.White;
}
private void treeView1_DragEnter(object sender, DragEventArgs e)
{
    
if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
    {
        e.Effect 
= DragDropEffects.Copy;
    }
    
else
    {
        e.Effect 
= DragDropEffects.None;
    }
}
private void treeView1_DragOver(object sender, DragEventArgs e)
{
    TreeNode node 
= treeView1.SelectedNode;
    
if (node != null)
    {
         node.BackColor 
= Color.White;
     }
     Point targetPoint 
= treeView1.PointToClient(new Point(e.X, e.Y));
     node 
= this.treeView1.GetNodeAt(targetPoint);
     
//TreeNode node = this.treeView1.GetNodeAt(e.X, e.Y);
    if (node != null)
     {
         treeView1.SelectedNode 
= node;
         treeView1.SelectedNode.BackColor 
= Color.LightBlue;
     }
}

在模仿中成长,在创新中成功

posted on 2009-07-17 14:43  huadust  阅读(493)  评论()    收藏  举报