winform中: datagridview发生以下异常: system.ArgumentException:参数无效

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了winform中: datagridview发生以下异常: system.ArgumentException:参数无效相关的知识,希望对你有一定的参考价值。

在system.Drawing.Image.FromStream
........

FromStream 异常,说明传入的stream参数无效,你需要确认,你的图片流是有效的 参考技术A 页面上加 EnableEventValidation = false 参考技术B 页面上加 EnableEventValidation = false ,FromStream 异常,说明传入的stream参数无效,你需要确认,你的图片流是有效的

Winform DataGridView控件添加行号

 

有很多种方法,这里介绍两种:

A:

控件的RowStateChanged事件中添加,RowStateChanged事件是在行的状态更改(例如,失去或获得输入焦点)时发生的事件:

1 e.Row.HeaderCell.Value = (e.Row.Index + 1).ToString();//添加行号
2 
3 //e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);

B:

控件的RowStateChanged事件中添加,RowStateChanged事件是在绘制 System.Windows.Forms.DataGridViewRow 后发生的事件:

1         private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
2         {
3             //添加行号
4             System.Drawing.Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Y, this.dataGridView1.RowHeadersWidth - 4, this.dataGridView1.ColumnHeadersHeight);
5             TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);//”TextFormatFlags.VerticalCenter | TextFormatFlags.Right“中“|”有增加的作用,此处添加了两种文本字符格式样式
6             //this.dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.FromArgb(192, 192, 255);//行标题单元格BackColor
7             //this.dataGridView1.RowHeadersDefaultCellStyle.BackColor = SystemColors.Control;
8         }

 

以上是关于winform中: datagridview发生以下异常: system.ArgumentException:参数无效的主要内容,如果未能解决你的问题,请参考以下文章

Winform 中DataGridView控件添加行标题

Winform DataGridView控件添加行号

Winform DataGridView控件添加行号

WinForm程序用使用List对象绑定DataGridView数据源

带有按钮、组合框和文本框的 C# WinForms (.NET Framework) DataGridView:使用按钮添加新行以添加组合框项时出错

排序DatagridView列后显示正确的行号[C#WinForm]