DataGridView throwing Exception in Default Error Dialog due to DataGridViewImageColumn

前端 未结 3 2188
孤独总比滥情好
孤独总比滥情好 2021-02-13 18:09

I am putting this up because it took far too long to find the answer on the web and this is probably a common problem - it is the second time i have experienced it on my app.

3条回答
  •  离开以前
    2021-02-13 18:51

    This problems is caused by some image and varbinary column types, my solution was creating other data datatable and setting all columns and cell values to string type:

                var clonedDT = dt.Clone();
    
                for (int i = 0; i < clonedDT.Columns.Count; i++)
                {
                    clonedDT.Columns[i].DataType = typeof(String);
                }
    
    
                for (int j = 0; j < dt.Rows.Count;j++ )
                {
                    var newRow = clonedDT.NewRow();
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {                        
                        newRow.SetField(i, Convert.ToString(item.Value.Rows[j]  [i]));
                    }
    
                    clonedDT.Rows.Add(newRow); 
                }
    

提交回复
热议问题