title: VB.NET How to remove selected rows from DataTable and update it to CheckedListBox?
body: <p>First I set up the DataTable as shown below. Added 3 columns with Desc, Price and The full string to display.</p>
  
  <pre><code>    checkBoxDT = New DataTable
      checkBoxDT.Columns.Add(New DataColumn With
                     {.ColumnName = "Desc", .DataType = GetType(String)})
      checkBoxDT.Columns.Add(New DataColumn With
                     {.ColumnName = "Price", .DataType = GetType(Decimal)})
      checkBoxDT.Columns.Add(New DataColumn With
                     {.ColumnName = "DisplayText", .DataType = GetType(String),
                     .Expression = "Desc + ' - RM ' + Price"})
  </code></pre>
  
  <p>Then, I create a new dataview and bind the CheckedListBox1 to the DataTable.</p>
  
  <pre><code>    checkListView = New DataView(checkBoxDT)
      checkListView.Sort = "Desc ASC, Price ASC"
      CheckedListBox1.DataSource = checkListView
      CheckedListBox1.DisplayMember = "DisplayText"
  </code></pre>
  
  <p>Here I add new items to the CheckedListBox1 with the code below</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim quan As Integer = 0
      Dim currentPrice As Decimal = 0.0
      If ComboBox2.SelectedIndex &gt; 0 Then
          quan = Convert.ToInt32(ComboBox2.Text.Trim())
          currentPrice = Convert.ToDecimal(TextBox3.Text.Trim())
          For i As Integer = 1 To quan
              checkBoxDT.Rows.Add({ComboBox1.Text, Convert.ToDecimal(TextBox3.Text)})
              totalItems = totalItems + 1
              totalPrice = totalPrice + currentPrice
          Next
      Else
          currentPrice = Convert.ToDecimal(TextBox3.Text.Trim())
          checkBoxDT.Rows.Add({ComboBox1.Text, Convert.ToDecimal(TextBox3.Text)})
          totalItems = totalItems + 1
          totalPrice = totalPrice + currentPrice
      End If
      TextBox5.Text = totalItems.ToString()
      TextBox4.Text = totalPrice.ToString()
  End Sub
  </code></pre>
  
  <p>But I am having problem in deleting the CheckedListBox1 items. Here is what I have tried.</p>
  
  <p>This is the delete button. I am trying to delete the items in CheckedListBox1 for all the selected items. Then show the right price in TextBox4. When I select only 1 item to be deleted, it works fine. But multiple item selected does not work properly. It deletes other item which is not selected as well.</p>
  
  <pre><code>Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
      Dim currentPrice As Decimal = 0.0
  
      While CheckedListBox1.CheckedItems.Count &gt; 0
          currentPrice = Convert.ToDecimal(CType(CheckedListBox1.SelectedItems(0), DataRowView).Item("Price").ToString())
          totalPrice = totalPrice - currentPrice
          totalItems = totalItems - 1
          checkListView.Delete(CheckedListBox1.SelectedIndex())
      End While
  
  
      TextBox4.Text = totalPrice.ToString()
      TextBox5.Text = totalItems.ToString()
  End Sub
  </code></pre>