以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  索引超出范围问题请教  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=140729)

--  作者:z769036165
--  发布时间:2019/9/12 11:42:00
--  索引超出范围问题请教

图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

出现索引超出范围,然后对应的副本表窗口_table1出现红×,点继续后执行的代码能全部正常执行完毕,代码执行的直接操作Datatable上,不是在副本表"窗口_table1"

而且BeforeShowErrorMessage中捕捉不了错误。


************** 异常文本 **************

System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。

参数名: index

   在 System.Collections.ArrayList.get_Item(Int32 index)

   在 C1.Win.C1FlexGrid.RowCollection.get_Item(Int32 index)

   在 C1.Win.C1FlexGrid.C1FlexGrid.DrawRow(PaintEventArgs e, Int32 row)

   在 C1.Win.C1FlexGrid.C1FlexGridBase.#adb(PaintEventArgs #tQ)

   在 C1.Win.C1FlexGrid.C1FlexGridBase.OnPaint(PaintEventArgs e)

   在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)

   在 System.Windows.Forms.Control.WmPaint(Message& m)

   在 System.Windows.Forms.Control.WndProc(Message& m)

   在 C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)

   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我在Try中,有
If  DataTables("表A").Find("单号 = \'"& dr &"\'") IsNot Nothing Then
                DataTables("表A").Find("单号 = \'"& dr &"\'")("状态") = "打开"
                DataTables("表A").Find("单号 = \'"& dr &"\'")("日期") = Now().Year & "-" & format(Now().Month,"00") & "-" & format(Now().Day,"00") & " " & Format(Now().Hour,"00") & ":" & format(Now().Minute,"00") & ":" & format(Now().Second,"00")
                DataTables("表A").Find("单号 = \'"& dr &"\'")("选择") = False
 End If
会不会是这个问题造成的,对副本表的原Datatable表操作的地方就只有这个地方。

--  作者:有点蓝
--  发布时间:2019/9/12 11:46:00
--  
理论上提示的错误应该和这段代码没有关系,去掉这段代码还有没有问题?

不过这个代码也有严重的问题。所有find的结果都应该判断才能使用

dim dr1 as datarow = DataTables("表A").Find("单号 = \'"& dr &"\'")
if dr1 isnot nothing then dr1("状态") = "打开"

--  作者:z769036165
--  发布时间:2019/9/12 12:45:00
--  
主要是这个现象很不常见,偶尔出现。
那段代码有判断啊!只是没有直接定义

--  作者:有点蓝
--  发布时间:2019/9/12 13:42:00
--  
多测试看能不能找出出错的规律