--》错误提示 :操作无效,原因是它导致对 SetCurrentCellAddressCore 函数的可重入调用。
解决方法:
private void dataGridPen_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dataGridPen.IsCurrentCellDirty) { dataGridPen.CommitEdit(DataGridViewDataErrorContexts.Commit); } }
--》点击单元格选中整行:
设置DataGridView的属性SelectionMode为FullRowSelect
--》设置不自动显示数据库中未绑定的列
this.dgvResult.AutoGenerateColumns = false;
--》设置默认的第一个空白列不显示
RowHeadersViible=false
--》DataGridView 常用样式设置
private void GridViewStyle(DataGridView dgv) { #region DataGridVeiw Style System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dataGridViewCellStyle1.BackColor = System.Drawing.Color.LightCyan; dgv.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; dgv.BackgroundColor = System.Drawing.Color.White; dgv.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240 dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240))))); dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy; dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dgv.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; dgv.EnableHeadersVisualStyles = false; dgv.GridColor = System.Drawing.SystemColors.GradientInactiveCaption; //dgv.ReadOnly = true; dgv.RowHeadersVisible = false; //建议改为true;为了以后显示序号。 dgv.RowTemplate.Height = 23; //dgv.RowTemplate.ReadOnly = true; #endregion }
本文来自博客园,作者:董锡振,转载请注明原文链接:https://www.cnblogs.com/dongxizhen/p/16645317.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人