Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET WPF列表框中的选定项-Can';t多次触发所选项目_Wpf_Vb.net_Listbox - Fatal编程技术网

VB.NET WPF列表框中的选定项-Can';t多次触发所选项目

VB.NET WPF列表框中的选定项-Can';t多次触发所选项目,wpf,vb.net,listbox,Wpf,Vb.net,Listbox,我正在将UserControl,ucRegisterItem加载到一个名为MainGrid的列表框中。 ucRegisterItem有一个唯一的ID,当在MainGrid内部单击该项时,我需要能够检索该ID 使用下面的代码,当加载ucRegisterItem的实例时,我可以单击每个项目一次并检索ID——但是如果我再次单击它,什么也不会发生。我可以添加一个新的ucRegisterItem并获得该ID,但同样,只需一次 我不确定我做错了什么 以下是UC ucRegisterItem代码: P

我正在将UserControl,ucRegisterItem加载到一个名为MainGrid的列表框中。 ucRegisterItem有一个唯一的ID,当在MainGrid内部单击该项时,我需要能够检索该ID

使用下面的代码,当加载ucRegisterItem的实例时,我可以单击每个项目一次并检索ID——但是如果我再次单击它,什么也不会发生。我可以添加一个新的ucRegisterItem并获得该ID,但同样,只需一次

我不确定我做错了什么

以下是UC ucRegisterItem代码:

    Public theOID As Integer
    Public Event OIDSelected(ByVal OID As Integer)

    Public Sub New(ByVal OID As Integer, ByVal Seat As Integer, ByVal Item As String, ByVal Qty As Double, ByVal Price As Double, ByVal SalesTax As Double, ByVal Total As Double, ByVal Optional Notes As String = "")

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        theOID = OID
        theSeat.Text = theOID 'Seat
        theProdName.Text = Item
        theQty.Text = Qty
        thePrice.Text = FormatCurrency(Price, 2)
        theTax.Text = FormatCurrency(SalesTax, 2)
        theTotal.Text = FormatCurrency(Total, 2)
        If Notes = "" Then
            ItemInfo.Children.Remove(ItemNotes)
        Else
            ActualNotes.Text = Notes
        End If

    End Sub

    Private Sub whatever_Selected(sender As Object, e As RoutedEventArgs) Handles whatever.Selected
        RaiseEvent OIDSelected(theOID)
    End Sub
End Class
下面是我将其加载到列表框中的位置:

    Public Sub AddListItem(ByVal OID As Integer, ByVal Seat As Integer, ByVal Item As String, ByVal Qty As Double, ByVal Price As Double, ByVal SalesTax As Double, ByVal Total As Double, ByVal Optional Notes As String = "")
        Dim newItem As New ucRegisterItem(OID, Seat, Item, Qty, Price, SalesTax, Total, Notes)

        newItem.Name = "item" & OID


        MainGrid.Items.Add(newItem)
        MainGrid.SelectedIndex = MainGrid.Items.Count - 1
        MainGrid.ScrollIntoView(MainGrid.SelectedItem)

        AddHandler newItem.OIDSelected, AddressOf ShoutItOut
    End Sub

    Public Sub ShoutItOut(sender As Object)


        'Setting the value of this mug.
        selectedVal = CInt(sender)
        MsgBox("Value: " & sender.ToString)


    End Sub
我添加了MsgBox以查看它将发送什么。我让MsgBox显示一次,但不是在第二次单击或在该特定项目上的任何单击时显示

任何帮助都将不胜感激


谢谢大家!

奥斯塔斯说得对。您订阅的是“选定”而不是“单击”,因此将事件处理程序更改为鼠标悬停或单击事件。

我非常确定这是预期的行为,因为当您第二次单击所选项目时,它不会再次“选择”,因此事件不会触发。您必须取消选择项目programmaticaly或订阅单击事件。感谢的Ostas。在我等待答复时,Articulous通过电话帮助我。感谢您抽出时间回答我的问题。:)