DataGridView Index -1 does not have a value 错误

遇到一个非常奇怪的问题,

一个DataGridView在装载数据后, 无论点击Column还是Cell都会报如下错误:

DataGridView Index -1 does not have a value 错误

查bing之后发现*都指向DataSource的问题。

于是查看自己的写法:

    var vt = dgvSummary.DataSource as List<MyTradeSummaryAtom>;
{
var atom = arg_atom;
if (null == atom.Strategy)
return ErrorObject.ReturnFalse("arg_atom的Strategy为Null");
var a = (atom.Strategy as Strategy_V1A1).Account;
var eo = ErrorObject.True;
var tsi = a.GetTradeSummaryInfo(_dtimeStart, _dtimeNext, out eo, 20000);
if (eo.IsFalse)
return eo;
vt.Add(tsi.全部交易概要.ToMyTradeSummaryAtom(atom));
} this.InvokeEx(() =>
{
dgvSummary.DataSource = null;
dgvSummary.DataSource = vt;
}
);

可以看到dgvSummary的DataSource在更新数据前后的对象其实是同一个List

改为:

    this.InvokeEx(() =>
{
dgvSummary.DataSource = vt.ToArray();
}

问题解决

上一篇:run fsck manually


下一篇:kumavis/obj-multiplex