Home Forums WPF controls Xceed DataGrid for WPF binding ItemsSource to a List<string>,automatically refresh

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24996 |

    Hello all, can anybody help me?
    My DataGrid do not automattically refresh after I added a new item to a property
    that is binded to ItemsSource.
    This is what I’m doing:
    xaml:
    <xcdg:DataGridControl Name=”testBinding”
    ItemsSource=”{Binding ElementName=window1, Path=ItemsSelected, Mode=OneWay}” >
    </xcdg:DataGridControl>

    ItemsSelected in C# code :
    public static DependencyProperty ItemsSelectedProperty =
    DependencyProperty.RegisterAttached(
    “ItemsSelected”, typeof(List<string>), typeof(Window1));

    List<string> ItemsSelected
    {
    get
    {
    return (GetValue(ItemsSelectedProperty) as List<string>);
    }
    set
    {
    SetValue(ItemsSelectedProperty, value);
    }
    }

    protected override void OnInitialized(EventArgs e)
    {
    base.OnInitialized(e);
    ItemsSelected = new List<string>();
    ItemsSelected.Add(“one”);
    ItemsSelected.Add(“two”);
    }

    Now, after I added a new item to ItemsSelected :
    ItemsSelected.Add(“three”);

    I expected that DataGrid automatically rebind (refresh) to ItemsSelected and show all items
    from ItemsSelected.
    This is not happend and I must manually make a refresh with Items collection
    testBinding.Items.Refresh();

    I’m doing or missing something?

    Imported from legacy forums. Posted by winnetou (had 1130 views)

    Xceed Support
    Member
    Post count: 5658

    List<T> does not implement change notification… Therefore, the DataGridControl has no way to determine that an item was added to the collection…

    The DataGridControl supports the following change notification mechanism:
    – IBindingList
    – INotifyCollectionChanged

    You will need to use a collection that implements either one of them so the grid can update when the list changes.

    The first interface is already implemented in the BindingList<T> class while the second is implemented by the ObservableCollection<T>.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 381 views)

    User (Old forums)
    Member
    Post count: 23064

    thanks Marcus

    Imported from legacy forums. Posted by winnetou (had 3546 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.