[英]Setting WPF RepeatBehavior to “none” in VB.net Code Behind
[英]How to remove a record from a Listbox control in my WPF application with VB.Net code behind
我知道以前曾發布過與我類似的問題,但我嘗試了各種建議,但似乎無濟於事。
這是我的問題:嘗試從列表框控件中刪除項目\\時,出現以下錯誤:
附加信息:使用ItemsSource時操作無效。 而是使用ItemsControl.ItemsSource訪問和修改元素。
我需要幫助,從帶有VB.Net代碼隱藏的WPF中的列表框中刪除項目。 當我單擊列表框中的一行時,我想從列表框中刪除該項目。 我創建對象“ ToLoadImages”的列表以加載到我的列表框中。
如何從列表框和列表對象“ ToLoadImages”中刪除所選項目?
請參閱下面的代碼:
“要加載的代碼”列表框
Private Sub GetListToLoad(ClaimNo As String)
Dim ta As New ImagesDataSetTableAdapters.usp_SELECT_ImageTableAdapter
Dim dt As ImagesDataSet.usp_SELECT_ImageDataTable = ta.GetData(1, _ClaimNo, True)
Dim dr As DataRow
ListToLoad = New List(Of ToLoadImages)
Dim i As Integer = 0
For Each dr In dt
Dim ImgSource2() As Byte = DirectCast(dr(7), Byte())
Dim stream2 As MemoryStream = New MemoryStream
stream2.Write(ImgSource2, 0, ImgSource2.Length - 1)
stream2.Seek(0, SeekOrigin.Begin)
bitMap2 = New BitmapImage
bitMap2.BeginInit()
bitMap2.StreamSource = stream2
bitMap2.EndInit()
ListToLoad.Add(New ToLoadImages(dr(0), bitMap2))
Next
ImageListBox.ItemsSource = ListToLoad
End Sub
'從列表框中檢索選定項目的代碼'在這里我要添加代碼,該代碼將從我的列表框中和'ToLoadImages'列表中刪除選定的項目。
Private Sub ImageListBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles ImageListBox.SelectionChanged
Try
Dim itemsToLoad As ToLoadImages
itemsToLoad = ImageListBox.SelectedItem
Dim imageID as String = itemsToLoad.ImgID.ToString
Catch ex As Exception
MsgBox("Error encountered.")
End Try
End Sub
類ToLoadImages
Public Class ToLoadImages
Private m_imgID As Integer
Private m_imageX As BitmapImage
Public Sub New(imgID As Integer, imagex As BitmapImage)
Me.m_imgID = imgID
Me.m_imageX = imagex
End Sub
Public Property ImgID() As Integer
Get
Return m_imgID
End Get
Set(ByVal value As Integer)
m_imgID = value
End Set
End Property
Public Property ImageX() As BitmapImage
Get
Return m_imageX
End Get
Set(ByVal value As BitmapImage)
m_imageX = value
End Set
End Property
End Class
使用ObservableCollection
而不是List
。
ObservableCollection
自動更新更改
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.