-1
好的,這段代碼是一個組合框中的項目列表,你必須選擇一個項目,然後選擇一個喜歡或不喜歡的單選按鈕然後點擊投票。結果列表框應該總計每次投票你點擊喜歡或不喜歡並且投票。當我點擊像並按下投票時,結果框中什麼也沒有顯示,但是當我不喜歡並且按下投票時,它顯示出來,並且總計正確,就像我按下並投票,所以它顯示每個1。它在程序運行的整個過程中保持這種狀態,所以如果我再打3次,它將不會在列表框中更新,直到我不喜歡並按下投票。如何編碼以顯示和更新喜歡和不喜歡的選票?Food Survey Application
這裏是我的代碼:
Public Class FoodSurveyForm
Dim votes As Integer(,) = New Integer(0 To 3, 0 To 1) {}
' handles Food Survey Form's Load event
Private Sub FoodSurveyForm_Load(sender As System.Object,
e As System.EventArgs) Handles MyBase.Load
foodsComboBox.SelectedIndex = 0 ' select first food in list
End Sub ' FoodSurveyForm_Load
Private Sub voteButton_Click(sender As System.Object, e As System.EventArgs) Handles voteButton.Click
Dim index As Integer = foodsComboBox.SelectedIndex
'if statement to add like and dislike votes
If likeRadioButton.Checked Then
votes(index, 0) += 1
ElseIf dislikeRadioButton.Checked Then
votes(index, 1) += 1
DisplayVotes()
End If
End Sub
Sub DisplayVotes() 'call DisplayVotes sub procedure
resultsListBox.Items.Clear()
'header for resultListBox
resultsListBox.Items.Add("Menu Item" & ControlChars.Tab & "Like" _
& ControlChars.Tab & "Dislike")
For count As Integer = 0 To foodsComboBox.Items.Count - 1
resultsListBox.Items.Add(foodsComboBox.Items(count).ToString & ControlChars.Tab & votes(count, 0) & _
ControlChars.Tab & votes(count, 1))
Next count
End Sub ' Display Votes
End Class ' FoodSurveyForm
沒關係!我知道了!! – Courtney 2014-10-27 19:56:25