0

ListBoxアイテムの追加DataTable、アイテムの移動はすべて機能しますが、削除は機能しません。イベントの一部として再ロードされない限り、に反映されDataTableますが、からすべてのアイテムがクリアされます。ListBoxSelectionChanged

Listbox.Items.Refreshを に設定しItemsSourceNothing、 に再割り当てしようとしましたDataTable

何か案は?

ありがとう

Private Sub Reports_BalanceSheet_NominalListBox_Delete(NomLB As String, DT As DataTable)
    Try
        Dim LB As ListBox = Reports_BalanceSheet_Grid.FindName(NomLB)
        If LB.SelectedIndex = -1 Then
            AppBoxValidation("No item has been selected for deletion!")
            Exit Sub
        End If
        Dim FR() As DataRow = DT.Select("ID = " & LB.SelectedValue, Nothing)
        Dim CatID As Integer = 0
        For Each row As DataRow In FR
            CatID = row("CatID")
            row.Delete()
        Next

        DT.AcceptChanges()
        Dim vDV As New DataView(DT)
        vDV.RowFilter = "FormID = " & FormID & " AND CatID = " & CatID
        vDV.Sort = "Position"
        DT = vDV.ToTable
        vDV = Nothing
        Dim i As Integer = 0
        For Each row As DataRow In DT.Rows
            row("Position") = i
            i += 1
        Next

        With LB
            .ItemsSource = DT.DefaultView
            .DisplayMemberPath = "Name"
            .SelectedValuePath = "ID"
        End With

    Catch ex As Exception
        EmailError(ex)
    End Try
End Sub
4

1 に答える 1