码迷,mamicode.com
首页 > Windows程序 > 详细

WinFrom - DataGridView控件右键选中记录并弹出菜单

时间:2015-07-01 15:55:12      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

dataGridView右键菜单并选中该行

程序代码:

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    dataGridView1.ClearSelection();
                    dataGridView1.Rows[e.RowIndex].Selected = true;
                    dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
                }
            }
        }

 

去掉带*好的左边的那一列:

把DataGridView 的RowHeadervisible设置成false

 

WinFrom - DataGridView控件右键选中记录并弹出菜单

标签:

原文地址:http://www.cnblogs.com/KTblog/p/4613173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!