Datagrdiview中的system.FormatException [英] system.FormatException in Datagrdiview
问题描述
如果 Hi, if ( .rows.Count> 0&& 此 foreach (DataGridViewRow dRow 此 用于 ( int i = 0;我< 此 .Columns.Count; i ++) (this.Rows.Count > 0 && this.Columns.Count > 0) 如果 (!(dRow.Cells [i] .GetType().Name).Equals( " DataGridViewTextBoxCell" )))
dRow.Cells [i] = if (!(dRow.Cells[i].GetType().Name).Equals("DataGridViewTextBoxCell"))
dRow.Cells[i] = 新 DataGridViewTextBoxCell(); ==>这段代码使我抛出异常System.Format Exception:单元格的格式化值具有错误的类型
} new DataGridViewTextBoxCell(); ==> this code throws me the exception System.Format Exception : Formatted value of the cell has a wrong type
} } } } 那是因为列包含单元格类型. 这篇关于Datagrdiview中的system.FormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
在我的应用程序中,我包括了Datagridview并使用Imagecell初始化了网格,通过编程对文本框单元格进行了编程.
并编写了代码,以使用不同的控制集重新初始化网格.
为此,请plz查看以下代码:
在此代码中,请考虑drow.cell [2]是一个DatagridviewImagecell....到DatagridViewTextBoxcell的.Cell [2]到那个时候我得到异常System.Format异常:单元格的格式化值具有错误的类型.
In my application, i have included Datagridview and initialized grid with Imagecell , textbox cells programatically.
and has written code to reinitialize the grid with different set of contols in it.
To do so , plz look into below code:
In this code, consider that the drow.cell[2] is a DatagridviewImagecell.... that time i am initializing that drow.Cell[2] to DatagridViewTextBoxcell that time i am getting the exception System.Format Exception : Formatted value of the cell has a wrong type.
{
dRow.Cells [i] .Tag = ;
dRow.Cells [i] .Value = 空 ;
{
foreach (DataGridViewRow dRow in this.Rows)
{
for (int i = 0; i < this.Columns.Count; i++)
{
dRow.Cells[i].Tag = null;
dRow.Cells[i].Value = null;
dRow.Cells[i].ReadOnly = false;
请告诉我为什么我遇到此异常.帮我解决.我可以理解问题的根本原因是什么.将单元格初始化为datagridviewtextboxcell时,会发生什么格式不匹配的情况.谢谢.
Please tell me why i am getting this exception. Help me to solve . i coulndt understand what is the root cause of the problem. What format mismatch happens while initializing the cell to datagridviewtextboxcell. Thanks.推荐答案
您必须分配列再次包含要更改类型的单元格.
Ex DataGridViewTextBoxColumn dgvtbc = new DataGridViewTextBoxColumn();
//set othe rproperties here
dataGridView1.Columns.RemoveAt(2);// the index you want to change
dataGridView1.Columns.Insert(2, dgvtbc);