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);
               }
            }

  • 相关阅读:
    一个页面通过iframe,获取另一个页面的form
    framework7 点取消后还提交表单解决方案
    sys模块
    logging模块
    MongoDB
    os.path模块
    Redis 复制、Sentinel的搭建和原理说明
    Linux环境下虚拟环境virtualenv安装和使用
    centos7 下通过nginx+uwsgi部署django应用
    NGINX实现负载均衡的几种方式
  • 原文地址:https://www.cnblogs.com/jose/p/2168601.html
Copyright © 2011-2022 走看看