DataGridView之UserControl遭遇Vista时的奇怪错误
灯火斑斓 2009-03-27 11:37:28 用DataGridView,BindingSource,BindingNavigator构建的UserControl在Windows XP, Windows 2003 Server上运行得好好的(是在Windows 2003 Server + VS2005),客户端安装到Vista上时会出错:
Message: BindingSource 不能是自己的数据源。请不要将 DataSource 和 DataMember 属性设置为循环引用 BindingSource 的值。
StackTrace:
在 System.Windows.Forms.BindingSource.get_Count()
在 System.Windows.Forms.CurrencyManager.get_Count()
在 System.Windows.Forms.DataGridViewCell.GetValue(Int32 rowIndex)
在 System.Windows.Forms.DataGridViewCell.get_Value()
在 ThreadForLabelPrint() 位置 D:\CS Project\Warehouse Management System\WMS DMR Launch Manager\MainForm.cs:行号 6918
代码如下:
foreach(DataGridViewRow dgvr in this.dbGridView12.dataGridView.Rows)
{
this.VarCompStock.PartNumber = dgvr.Cells["PartNumber"].Value.ToString(); //line: 6918
this.VarCompStock.MfgPartNumber = dgvr.Cells["MfgPartNumber"].Value.ToString();
this.VarCompStock.Manufacturer = dgvr.Cells["VendorCode"].Value.ToString();
this.VarCompStock.ComponentID = dgvr.Cells["ComponentID"].Value.ToString();
......生成标签代码略
}
一般一次可能要打印几十到几百张标签,DataGridView中的记录会同步移动。经常会打印完几十张标签后就出现此错误。但从出错的代码来看,仅仅是从DataGridView当前行的单元格中读取数据而已。百思不得其解,网上也查不到该问题。