Reputation: 4900
I already had this stuff working in another project but now it does not. I have no more idea why.
{Binding}
Dim MyList As New List(of myclass)
DataGrid.DataContext = MyList
when Instance is createdI added my first class on the list
MyList.Add(New myclass())
now, this item is visible. but after creating the instance and after the datagrid is visible, the rows do not update.
MyList.Add(New myclass())
and no second row is visible.
Only when doing
MyDataGrid1.Items.Refresh
the items are updated correctly.
But the List(of ) class already included the INotifyPropertyChanged
interface as far as I understand.
Any ideas why it fails?
here some additional code
<DataGrid.Columns>
<DataGridTextColumn Header="N°" Binding="{Binding Path=LineNumber, StringFormat='{}{0:000}'}" Width="SizeToCells" MinWidth="30" IsReadOnly="True" />
<DataGridTextColumn Header="HEX" Binding="{Binding HexText}" Width="SizeToHeader" MinWidth="80" IsReadOnly="True" FontWeight="Bold" />
<DataGridTextColumn Header="TextNormalized" Binding="{Binding Description}" Width="*" MinWidth="80" IsReadOnly="True" FontSize="12" />
</DataGrid.Columns>
</DataGrid>
Some codebehind:
Private ListData As New List(Of clsHexRowData)
Instance:
Public Sub New()
' This call is required by the designer.
InitializeComponent()
Me.dgv.ItemsSource = Me.ListData
Me.ListData.Clear()
Dim item As New clsQueueItem
item.FromString("Hallo")
Me.AddItem(item)
End Sub
this is visible, but when adding new rows after initializing the page, the items are not updated and a dgv.Items.Refresh
is needed which I don't understand why.
Upvotes: 0
Views: 327
Reputation: 22435
use ObservableCollection(of myclass) instead of list. you will see the changes when you add or remove items.
EDIT
//add
Application.Current.Dispatcher.BeginInvoke((Action)(()=> { Me.ListData.Add(new Item());}))
Upvotes: 1