title: Replace the same line in multiple ListBoxes using vb.net
body: <p>I have 4 listboxes named: <code>courseNameListBox</code>, <code>gradeListBox</code>, <code>creditsListBox</code>, and <code>qualityPointsListBox</code>. Elsewhere in my program, a total course average is calculated and then courseName, grade, credits, and qualitypoints for that course are transferred into their respective ListBoxes. I'm trying to make it so that if the user edits a particular course, like adding more grades for example, when they transfer that new information to the afore mentioned Listboxes, if the courseName already exists, it should replace the same line in all 4 ListBoxes with the new data from that particular course instead of adding a new line for the same course. I hope that makes sense.</p>
  
  <p>I can find and replace the courseNameListBox.item just fine, but I'm having a real difficult time figuring out how to connect the other 3 ListBox lines to <code>courseNameListBox.item</code> line.</p>
  
  <pre><code>  ElseIf courseNameListBox.Items.Contains(courseName) Then
  
       dim courseName as string = nameOfCourseTextBox.Text
       dim credits as integer = 0
       dim average as decimal = 0
       credits = Val(creditsTextBoxt.Text)
       average = Val(averageResultLabel.text)
  
       For i = 0 To courseNameListBox.Items.Count - 1
         If courseNameListBox.Items(i).ToString.Contains(courseName) Then
           courseNameListBox.Items(i) = courseNameListBox.Items(i).ToString.Replace(courseName, courseName)
         End If
       Next
  
    Else
  
          ' add course Name to course Name ListBox
          courseNameListBox.Items.Add(nameOfCourseTextBox.Text)
  
          ' add credits to credits ListBox
          creditsListBox.Items.Add(creditsTextBox.Text)
  
          Select Case average
             Case Is &gt;= A
                gradeListBox.Items.Add("A")
             Case Is &gt;= B
                gradeListBox.Items.Add("B")
             Case Is &gt;= C
                gradeListBox.Items.Add("C")
             Case Is &gt;= D
                gradeListBox.Items.Add("D")
             Case Is &lt;= F
                gradeListBox.Items.Add("F")
          End Select
  
          Select Case average
             Case Is &gt;= A
                qualityPointsListBox.Items.Add(credits * Val(aLetterGradeQualityPointsTextBox.Text))
             Case Is &gt;= B
                qualityPointsListBox.Items.Add(credits * Val(bLetterGradeQualityPointsTextBox.Text))
             Case Is &gt;= C
                qualityPointsListBox.Items.Add(credits * Val(cLetterGradeQualityPointsTextBox.Text))
             Case Is &gt;= D
                qualityPointsListBox.Items.Add(credits * Val(dLetterGradeQualityPointsTextBox.Text))
             Case Is &lt;= F
                qualityPointsListBox.Items.Add(credits * Val(fLetterGradeQualityPointsTextBox.Text))
          End Select
    End If
  </code></pre>
  
  <p>I have tried, among many other things:</p>
  
  <pre><code>     dim courseName as string = nameOfCourseTextBox.Text
       dim credits as integer = 0
       dim average as decimal = 0
       credits = Val(creditsTextBoxt.Text)
       average = Val(averageResultLabel.text)
  
       For i = 0 To courseNameListBox.Items.Count - 1
         If courseNameListBox.Items(i).ToString.Contains(courseName) Then
           courseNameListBox.Items(i) = courseNameListBox.Items(i).ToString.Replace(courseName, courseName)
         End If
       Next
       For C = 0 To creditsListBox.Items.Count - 1
          creditsListBox.Items(C) = creditsListBox.Items(C).ToString.Replace(credits, credits)
       Next
  </code></pre>
  
  <p>But that just replaces every line in the <code>creditsListBox</code> with the new <code>credits</code> value instead of just the line with the same <code>courseName</code>. So, how can I connect the line with the specified <code>courseName</code> in the <code>courseNameListBox</code> with the same line in the other 3 ListBoxes?</p>