Why isn't the subitem displayed on the contextMenuStrip when called on the right-click event on the DatagridView?

81 Views Asked by At

When I call the context menu the DataGrdiView does not show the menu sub items. But if I call this menu by right clicking on the form, then everything works correctly. The photo shows the same menu. Called on the form and called on the DataGridView. Why can this be so?

enter image description here

    private void ContextMenuStripNeeded(object sender,
       DataGridViewCellContextMenuStripNeededEventArgs e, DataGridView dataGrid)
    {
        if (e.RowIndex > -1 && e.ColumnIndex > -1)
        {

            dataGrid.CurrentCell = dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex];
            e.ContextMenuStrip = this.contextMenuCellsDataGridView;
            idCurrentTask = dataGrid.Rows[e.RowIndex].Cells[0].Value.ToString();

        }
    }

        private void ShowContextMenuobject(object sender, MouseEventArgs e, DataGridView dataGrid)
    {
        if (e.Button == MouseButtons.Right)
        {
            try
            {
                var hti = dataGrid.HitTest(e.X, e.Y);
                dataGrid.ClearSelection();
                dataGrid.CurrentCell = dataGrid.Rows[hti.RowIndex].Cells[0];
                idCurrentTask = dataGrid.Rows[hti.RowIndex].Cells[0].Value.ToString();

            }
            catch { }
        }
    }

    private void HandlerControls() {
        dgvDayTask.RowTemplate.ContextMenuStrip = contextMenuCellsDataGridView;
        dgvWeekTask.RowTemplate.ContextMenuStrip = contextMenuCellsDataGridView;
        dgvFutureTask.RowTemplate.ContextMenuStrip = contextMenuCellsDataGridView;
    }

0

There are 0 best solutions below