单元格 右键选择栏

来源:互联网 发布:linux 查看服务器域名 编辑:程序博客网 时间:2024/06/05 10:52

 private void xxx_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            e.Control.ContextMenuStrip = cMSSetValu;
        }

  private void XXXl_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {

try
            {
                DataGridView view = sender as DataGridView;
               
                //点击的是鼠标右键,并且不是表头
                if (e.Button == MouseButtons.Right && e.ColumnIndex > 0 && e.RowIndex > -1)
                {
                    //右键选中单元格
                    view.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
                    string itemNo = view.Rows[e.RowIndex].Tag.ToString();
                    var currentItem = signItemList.Find(s => s.ItemNo == itemNo);
                    if (currentItem != null && !string.IsNullOrWhiteSpace(currentItem.ValueList))
                    {
                        view.ContextMenuStrip = cMSSetValu;
                        cMSSetValu.Items.Clear();
                        var item = currentItem.ValueList.Split(',');
                      
                        _rowindex = e.RowIndex;
                        _columnindex = e.ColumnIndex;
                        Currentview = view;
                       
                    }
                }
                else
                {
                    view.ContextMenuStrip = null;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

        }

0 0
原创粉丝点击