I currently have a working listbox that is binded to a database, but I'm trying to add another column to the listbox but now it doesn't work. What am I missing?
Working and populates Listbox fine,
<ListBox HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource ListViewDataCurCmd}}" Margin="67,36,0,41" Name="lvwCurrCmd" SelectionMode="Multiple" Width="110" />
Not working and nothing populates
<ListBox HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource ListViewDataCurCmd}}" Margin="67,36,0,41" Name="lvwCurrCmd" SelectionMode="Multiple" Width="110">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Source={StaticResource ListViewDataCurCmd}}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Perhaps I don't quite understand how to populate columns, only the whole listbox. Do we populate by column or are we creating textblocks to use as 'rows' in the listbox?
Edit: How I declare my Observable Collections in xaml as well as the class it's populated in
xaml
<Window.Resources>
<CollectionViewSource
Source="{Binding Source={x:Static Application.Current}, Path=AllCmd}"
x:Key="ListViewDataAllCmd" />
<CollectionViewSource
Source="{Binding Source={x:Static Application.Current}, Path=CurCmd}"
x:Key="ListViewDataCurCmd" />
</Window.Resources>
DataBinding.xaml.vb
Private AllCmd_Renamed As New ObservableCollection(Of String)()
Private CurCmd_Renamed As New ObservableCollection(Of String)()
Private fieldToReturn As New ObservableCollection(Of String)()
Private valueToReturn As New ObservableCollection(Of String)()
Public Sub AppStartup(ByVal sender As Object, ByVal args As StartupEventArgs)
LoadAllCommandsDS()
Dim mainWindow As New MainWindow()
'mainWindow.Show()
End Sub
Private Sub LoadAllCommandsDS()
Dim sSql As String = "SELECT * FROM Steps"
Dim ds As DataSet
Dim _List As String = ""
ds = SQL(sSql)
For i = 0 To ds.Tables(0).Rows.Count - 1
_List = ds.Tables(0).Rows.Item(i).Item(1).ToString
Me.AllCmd.Add(_List)
Next
End Sub
Public Property AllCmd() As ObservableCollection(Of String)
Get
Return Me.AllCmd_Renamed
End Get
Set(ByVal value As ObservableCollection(Of String))
Me.AllCmd_Renamed = value
End Set
End Property
Public Property CurCmd() As ObservableCollection(Of String)
Get
Return Me.CurCmd_Renamed
End Get
Set(ByVal value As ObservableCollection(Of String))
Me.CurCmd_Renamed = value
End Set
End Property
ListViewinstead, which has built-in support for columns