导航

dataGridView右键菜单 右键菜单中取数据

Posted on 2009-05-22 16:34  kingwangzhen  阅读(895)  评论(0编辑  收藏  举报

/// <summary>
        /// dataGridView右键菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvSalesOrderInput_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if(e.Button==MouseButtons.Right)
            {
                //if (dgvSalesOrderInput.CurrentCell.OwningColumn.Name == "OrderPigVariety")
                if(e.ColumnIndex==7)
                {
                    dgvSalesOrderInput.Columns["OrderPigVariety"].ContextMenuStrip = cmpVariety;
                }
            }
        }

/// <summary>
        /// 从右键菜单中取数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmpVariety_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            dgvSalesOrderInput.CurrentCell.Value = e.ClickedItem.Text.Trim();
        }