VB.NET中的索引范围异常的奇怪问题

发布于 2025-01-22 02:50:21 字数 1071 浏览 2 评论 0原文

我在VB.NET(2019)项目中有一个DGV,并且在特定行索引中复制了单元格,但是AM遇到了一个奇怪的问题:

    TXTItemDetail.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(1).Value
    TXTOuterpackQTY.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(2).Value
    TXTOuterpackName.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(3).Value
    TXTItemCodeSelected.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(4).Value

    TXTCGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(7).Value
    TXTSGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(8).Value
    TXTIGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(9).Value
    TSSLHSNCode.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(10).Value
    TXTItemCode.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(11).Value

    'Error is thrown at the line below!!
    TXTRate.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(5).Value.ToString

请注意,在生成错误的线上,单元格索引在5时为5该代码已经在较早的代码行中贯穿了更高的索引,直至单元11。然而,在这种情况下会生成范围错误。 我能确定的是,我需要按顺序将代码线置于单元号的出现方式。例如,如果我在4后放置5个单元格5,则不会抛出此错误。

我在许多地方都使用过这种代码,但是从未遇到过这种类型的问题。 VB可能是某种线程问题吗?

谢谢。

I have a DGV in a VB.NET(2019) project and I copy the cells at specific row index, but am experiencing a strange issue:

    TXTItemDetail.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(1).Value
    TXTOuterpackQTY.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(2).Value
    TXTOuterpackName.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(3).Value
    TXTItemCodeSelected.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(4).Value

    TXTCGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(7).Value
    TXTSGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(8).Value
    TXTIGST.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(9).Value
    TSSLHSNCode.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(10).Value
    TXTItemCode.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(11).Value

    'Error is thrown at the line below!!
    TXTRate.Text = DGVItemSearch.Rows(ItemEnteredRow).Cells(5).Value.ToString

Note that on the line on which the error is being generated, the cell index is at 5 while the code has already run through on even higher indexes in the earlier lines of code, going up to cell 11. Yet, an out of range error is generated at this instance.
What I could determine was that I need to place the lines of code in sequence of how the cell numbers appear. For example, if I place cell 5 after 4, this error will not be thrown.

I have used this type of code in many places, but never came across this type of an issue. Could it be some kind of threading issue in VB?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文