尝试从表单、列表添加到另一个表单和列表时,帮助解决 NULL 错误。

Hui Liu-MSFT 46,961 信誉分 Microsoft 供应商
2024-03-29T07:13:23.6266667+00:00
Public Sub AddPrintBook() Select Case ShoppingCart.lstCart.Items.Add(lstPrintBooks.SelectedIndex) '"""""Getting a NULL error here. """""Copy

        Case 0
            strSelectedBook = strYourWay
            decSubTotal += decYourWay
            decShippingTotal += decShippingTotal
        Case 1
            strSelectedBook = strHistoryScotland
            decSubTotal += decHistoryScotland
            decShippingTotal += decShippingTotal
        Case 2
            strSelectedBook += decCalculus
            decSubTotal += decHistoryScotland
            decShippingTotal += decShippingTotal
        Case 3
            strSelectedBook = strRelax
            decSubTotal += decRelax
            decShippingTotal += decShippingTotal

    End Select

End Sub

Note:此问题总结整理于:Help with NULL error, when trying to add from a form, a list, to another form and list.

VB
VB
Microsoft 开发的一种面向对象的编程语言,其在 .NET Framework 上实现。 以前称为 Visual Basic .NET。
83 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Jiale Xue - MSFT 41,116 信誉分 Microsoft 供应商
    2024-03-29T07:28:06.7133333+00:00

    请看下面的例子: 我在 form1 上有 listbox1,在 form2 上有 listbox1。 表格 1:

    Public Class Form1  
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            Dim frm2 As Form2 = New Form2(Me)  
            frm2.Show()  
        End Sub  
    End Class  
    

    表格2:

    Public Class Form2  
        Private ReadOnly frm1 As Form1  
        Public Sub New(ByVal form1 As Form1)  
            frm1 = form1  
            InitializeComponent()  
        End Sub  
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
            ListBox1.Items.Add(frm1.ListBox1.SelectedIndex)  
        End Sub  
    End Class  
    

    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。

    注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助