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

  • 相关阅读:
    HDUOJ---------(1045)Fire Net
    HDUOJ----(1175)连连看
    HDUOJ-----(1072)Nightmare(bfs)
    deque容器的运用一点一点积累
    HDUOJ----(1016)Prime Ring Problem
    HDUOJ----Safecracker(1015)
    hduoj---Tempter of the Bone
    VC6.0设置注释快捷键
    nyoj------------找球号(一)
    set 容器 的全解(转)
  • 原文地址:https://www.cnblogs.com/jose/p/2168601.html
Copyright © 2011-2022 走看看