zoukankan      html  css  js  c++  java
  • c#中contextMenuStrip与datagridview使用CellMouseDown事件及treeview使用mousedown事件

     //对于datagridview使用CellMouseDown事件

    private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) 

    if (e.Button == MouseButtons.Right) 

       if (e.RowIndex >= 0) 
       { 
        dataGridView.ClearSelection(); 
        dataGridView.Rows[e.RowIndex].Selected = true; 
        dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; 
        contextMenuStrip_ListViewItemRightClick.Show(MousePosition.X, MousePosition.Y); 
       } 

    }

    //对于treeview可以使用mousedown事件

    方法一:
    private void treeView1_MouseDown(object sender, MouseEventArgs e) 

    if (e.Button == MouseButtons.Right) 

    TreeNode node = this.treeView1.GetNodeAt(e.Location); 
    if (node != null) 

    this.treeView1.SelectedNode = node; 


    }

    方法二:
    void jcsTreeView1_MouseDown(object sender, MouseEventArgs e)
            {
               System.Windows.Forms.TreeViewHitTestInfo hittestinfo = this.jcsTreeView1.HitTest(e.X ,e.Y);
               
    if (hittestinfo.Node != null)
               {
                   TreeViewHitTestLocations loc = hittestinfo.Location;
                   
    if(loc == TreeViewHitTestLocations.Label )
                     MessageBox.Show(hittestinfo.Node.Text);
               }
            }

  • 相关阅读:
    17.正则表达式
    16.os模块-shutil模块-tarfile压缩模块
    15.序列化模块-时间模块-zip压缩模块
    第一章 单变量线性回归
    如何跑通MonoRTM模型的官方例子
    PHP命名规范
    js中要声明变量吗?
    php抓取网站图片源码
    InnoDB和MyISAM区别总结
    php分页代码。
  • 原文地址:https://www.cnblogs.com/jose/p/2168601.html
Copyright © 2011-2022 走看看