注册:Form加载窗体代码
/// <summary> /// 窗体加载Form1 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1(object sender, EventArgs e) { //单元格内容点击 this.dataGridView1.CellContentClick += DataGridView1_CellContentClick; //单元格点击 this.dataGridView1.CellClick += DataGridView1_CellClick; //选中进入编辑状态事件 this.dataGridView1.CellBeginEdit += DataGridView1_CellBeginEdit; //用户是否可以调整所有列的列宽 this.dataGridView1.AllowUserToResizeColumns = false; //用户是否可以调整所有行的行高 this.dataGridView1.AllowUserToResizeRows = false; //禁止指定行或者列的Resize this.dataGridView1.Columns[0].Resizable = DataGridViewTriState.False; this.dataGridView1.Rows[0].Resizable = DataGridViewTriState.False; //开启提示 this.dataGridView1.ShowCellToolTips = true; dataGridView1[1, 1].ToolTipText = "测试下面的CellToolTipTextNeeded"; //在需要单元格的工具提示文本时发生。 //this.dataGridView1.CellToolTipTextNeeded += DataGridView1_CellToolTipTextNeeded; //this.contextMenuStrip1自己添加控件绑定即可 dataGridView1.ContextMenuStrip = this.contextMenuStrip1; //ContextMenuStrip设定 CellContextMenuStripNeeded this.dataGridView1.CellContextMenuStripNeeded += DataGridView1_CellContextMenuStripNeeded; //CellFormatting 事件处理方法 this.dataGridView1.CellFormatting += DataGridView1_CellFormatting; //CellParsing 事件处理方法 this.dataGridView1.CellParsing += DataGridView1_CellParsing; }