1

DataGridViewにcontextMenuがあります。

これは、selectedRowで操作するためのオプションを示しています。

ユーザーは、左クリックして行を選択し、次に右クリックしてコンテキストメニューを開く必要があります。

leftClicを省略したい、つまり-rightClickでdgvRowを選択し、同時に-contextMenuを開きます。

出来ますか ?

4

1 に答える 1

1

ここでこれを試してみてください。

datagridview_MouseDownイベントに追加します

    private void dgvPermit_MouseDown(object sender, MouseEventArgs e)
    {
        DataGridView dgv = (DataGridView)sender;
        DataGridView.HitTestInfo Hti;
        if (e.Button == MouseButtons.Right)
        {
            Hti = dgv.HitTest(e.X, e.Y);
            if (Hti.Type == DataGridViewHitTestType.Cell)
            {
                if (!((DataGridViewRow)(dgv.Rows[Hti.RowIndex])).Selected)
                {
                    dgv.ClearSelection();
                    ((DataGridViewRow)dgv.Rows[Hti.RowIndex]).Selected = true;
                }
            }
        }

    }
于 2012-05-24T16:04:22.910 に答える