1.一种最简单的是直接拖ContextMenuStrip控件
2.第二种是在后台写:
1 //ldt为已知table 2 3 DataGridView dg = new DataGridView(); 4 dg.DataSource=ldt; 5 ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); 6 contextMenuStrip.Items.Add("Edit"); 7 contextMenuStrip.Items.Add("Add"); 8 dg.Columns[t].HeaderCell.ContextMenuStrip = contextMenuStrip;