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

  • 相关阅读:
    jQuery中$.proxy()的原理和使用
    JS中各种宽度、高度、位置、距离总结
    js中得call()方法和apply()方法的用法
    google浏览器翻译失败解决方案
    js区分移动设备与PC
    知识积累
    Django
    leetcode 27.Remove Element
    leetcode 28. Implement strStr()
    21. Merge Two Sorted Lists
  • 原文地址:https://www.cnblogs.com/jose/p/2168601.html
Copyright © 2011-2022 走看看