2016-02-18 45 views
0

我創建了一個列表視圖,它有2列,第一列代表英文單詞,第二列代表法語單詞。當我選擇一行並按下按鈕時,我想生成一個代表所選單詞的聲音。 我以爲我可以識別每一行,當按下按鈕時,將會使用正確的聲音文件,這是我的代碼,但它是絕對垃圾......只要它能工作,我就可以開放任何東西:)從列表視圖中選擇一個項目並生成聲音文件

Private Sub ListenBtn_Click(sender As System.Object, e As System.EventArgs) Handles ListenBtn.Click 
    Dim x As Integer 
    x = 0 
    If ListView1.SelectedItems.Count > 0 Then 
     ListView1.Items(0) = x + 1 
     ListView1.Items(1) = x + 2 
    End If 
    Select Case x 
     Case 1 = My.Computer.Audio.Play(My.Resources.hello, AudioPlayMode.WaitToComplete) 
     Case 2 = My.Computer.Audio.Play(My.Resources.goodbye, AudioPlayMode.WaitToComplete) 
    End Select 
End Sub 
+1

不清楚到底是什麼你正在做。列表視圖是否允許多個選擇?你爲什麼要更新listview中的項目? –

+1

'x = ListView1.SelectedItems(0).Index' – Plutonix

回答

0

有幾種方法可以解決這個,但看到你的名字是如何「MassiveNoob」,我會盡量保持這個儘可能的簡單。

首先在設計視圖中,雙擊這個按鈕,如果你正在使用Visual Studio(我假設你是),並在單擊事件中,添加以下..

if listview1.selecteditems.count > 0 then 

     If listview1.SelectedItems(0).Text = "<Whatever is in column 1 of your row>" Then 
      My.Computer.Audio.Play(My.Resources.hello, AudioPlayMode.WaitToComplete) 
     ElseIf listview1.SelectedItems(0).Text = "<Whatever is in column 2 of your row>" Then 
      My.Computer.Audio.Play(My.Resources.goodbye, AudioPlayMode.WaitToComplete) 
     End If 
    End If 
相關問題