추가 방법 ListView
바인딩을 통해 Entity Framework/Linq를 통해 항목을 추가 하시겠습니까?Entity Framework/Linq에 의해 바인딩을 통해 ListView 항목을 추가하는 방법
<ListView x:Name="lstvw_Overview" HorizontalAlignment="Left" Height="310" Margin="11,89,0,0" VerticalAlignment="Top" Width="676">
<ListView.View>
<GridView>
<GridViewColumn Header="Adresse" DisplayMemberBinding="{Binding address}"/>
</GridView>
</ListView.View>
</ListView>
이
Public Sub New()
Initialize()
End Sub
Dim address As String
Dim items As ObservableCollection(Of Uebersicht)
Public Structure Uebersicht
Private _address As String
Public Property address As String
Get
Return _address
End Get
Set(value As String)
_address = value
End Set
End Property
End Structure
Sub Initialize()
InitializeComponent()
fillListView()
End Sub
Sub fillListView()
Using container As New infrastrukturDB_TESTEntities1
Dim mailAddressList = From tbl_unzustellbarAdressen In container.tbl_unzustellbarAdressen
For Each mail In mailAddressList
address = mail.unzustellbarMail.ToString()
Try
items.Add(New Uebersicht With {.address = address})
Catch ex As Exception
MessageBox.Show("Error")
End Try
Next
End Using
End Sub
EDIT 내 코드는 다음과 같습니다 :
는 여기 바인딩으로 XAML에서 내 ListView
을받은 ObserverableCollection
을 시도했지만 지금은 NullReferenceException
있어! 내가 디버깅 경우 는, 주소가 null가 아닌 데이터를 .. 가지고
당신은 당신이에 itemSource로 연결 무엇입니까 ObservableCollection에이 .xaml. VB에서 작동하는 방법을 잘 모르지만 비슷한 것이 있어야합니다. itemSource를 사용하지 않을 때는 Dispatcher에게 INotifyPropertyChanged를 사용하여 목록을 업데이트하라고 지시해야하지만 다시 C#에서만 알 수 있지만 솔루션 검색을위한 단서를 제공 할 수 있습니다. – Nekeniehl
@Nekeniehl ObservableCollection은 .NET Framework 클래스이므로 지원되는 모든 언어로 사용할 수 있습니다. – Clemens
@Raizzen ".xaml의 itemSource로 링크"는 ListView의 ItemsSource 속성을 항목 클래스의 ObservableCollection에 바인딩해야 함을 의미합니다. 'DisplayMemberBinding = "{Binding address}"'라고 쓰면 항목 클래스는'address'라는 이름의 public 속성을 갖게됩니다. – Clemens