Having trouble binding list/grid to collection

I have set up a grid and bound it to a collection. I can edit the items in the collection through my grid and the changes get propagated to the collection. And, the GUI is showing everything in the collection at the time the ItemSource is set. But, I am programmatically changing some of the items in the collection (after the ItemSource is set) and these changes aren't reflected in the grid/GUI. Is there something else I need to do in order to get it to refresh. FYI, for the fields I want to edit (MoveToResource, ResourceKey, and Resource Type), I have set the mode to TwoWay. Below is my grid.

<ListView Name="lstXAMLStrings" Margin="5" Grid.Row="1"> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="Extract?"> <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox Content="" IsChecked="{Binding Path=MoveToResource, Mode=TwoWay}" ></CheckBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Text"> <GridViewColumn.CellTemplate> <DataTemplate> <local:RichTextBlock RichText="{Binding Path=FormattedMatchedLines}" TextWrapping="Wrap" Width="650"></local:RichTextBlock> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Key Name"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=ResourceKey, Mode=TwoWay}" Width="150"></TextBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Resource Type"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding Source={StaticResource odp}}" SelectedItem="{Binding Path=Resource, Mode=TwoWay}"></ComboBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView.Columns> </GridView> </ListView.View> </ListView>

-------------Problems Reply------------

You need to make sure that your collection items implement INotifyPropertyChanged.

If each item you're changing programatically (correctly) implements that, your ListView/GridView will stay current.

This will work if you modify your collection items programatically, or in another screen.

Does your [view]model class implement INotifyPropertyChanged and fire the event whenever the property set accessor is used?

You need to make sure that the collection itself that you're databinding to is an observable collection (a class that implements the INotifyCollectionChanged interface). You might be able to alternatively roll your own class that implements INotifyCollectionChanged, but that's the only reason ObservableCollection exists so it could save you some time.

There's an msdn article on how to do it.

Category:c# Views:1 Time:2009-10-16

Related post

  • WPF MVVM: how to bind GridViewColumn to ViewModel-Collection? 2010-04-15

    In my View I got a ListView bound to a CollectionView in my ViewModel, for example like this: <ListView ItemsSource="{Binding MyCollection}" IsSynchronizedWithCurrentItem="true"> <ListView.View> <GridView> <GridViewColumn Header=

  • Selectively Binding Data To a Collection 2011-03-31

    I want to selectively bind data in a collection to different UI elements. For instance I have a collection of objects where each object has a property which describes the type of that object. I am currently using a DataTemplate to categorise the elem

  • how to bind the grid view to complex object 2012-01-16

    public class BE_RoomRateService { public IQueryable<RoomRateWithRoomType> RoomRateForAdmin() { var query= from rate in db.BE_RoomRates join room in db.BE_Rooms on rate.RoomId equals room.RoomId where rate.Status!=3 && room.Status!=3 sel

  • How do you bind a grid's children to a list? 2009-09-08

    In my ViewModel I have a list of items that I would like a grid in my view to bind to (the items will be the grids children). The list is a list of view models for the items. How do you bind a grid to the list (I can access .children in code but not

  • Trouble binding command to button in WPF 2010-05-10

    I've got a button in a ribbon I've implemented and having trouble binding to a command. The ribbon is in a UserControl named AppRibbon. The AppRibon control has a public property called SelectedModule which has a property named RenameModuleCmd. When

  • Trouble binding JSON data to JqGrid 2010-08-10

    I am having a lot of trouble binding my Json data to a JqGrid. In my Default.aspx.cs I have the following method : [WebMethod] public static string GetData() { CustomerHelper C = new CustomerHelper(); var data = C.GetAllCustomersSerialized(); return

  • Having trouble binding the Visibility of a ContentPresenter in WPF 2010-09-03

    I have the following XAML: <UserControl.Resources> <DataTemplate x:Key="ExpanderTemplate"> <Grid> <Rectangle Stroke="Black" StrokeThickness="1" Width="10" Height="10" Fill="White" /> <Rectangle Stroke="Black" StrokeThicknes

  • How to bind a grid or parsed XML data to a custom Windows Installer User Interface Dialog Box? 2010-11-23

    I'm creating a C# Windows Installer (using a C# Setup Project) for an application that I'm deploying and I have a problem with the limited UI controls. Throughout the install process, I am logging all the installer activity to an XML file, so in the

  • Model binding two or more collections 2010-12-11

    Has anyone had any luck model binding two or more collections using the code posted by Phil Haack here: Model Binding To A List? As an example, I have the below code. public class Book { public string Name { get; set; } } public class Author { public

  • Hierarchy data binding to grid in a windows application 2012-02-15

    I have data setup like this.. Transaction -Name -ID -Amount -Tags <-- Array of Tags - Name In a website, I could just loop through the tags and create spans of each tag with a link, I'm trying to figure out how to add this structure to a windows f

  • How to bind two grid each other like master-detail represent in DevExpress Winform 2014-08-12

    I am wondering that how to bind two grid each other like master detail represent? For example; I have two grid. Orders and Order detail. Order detail is placed next of the Orders. I want to make a dynamic filter that can make rows hide or visible in

  • Trouble binding command in grid menu item 2011-01-13

    I have a grid that's inside a usercontrol derived class called MediatedUserControl. I'm adding a context menu to let the user delete an item, but I've been unable to figure out how to bind the command to my command property. I'm using MVVM and my vie

  • Binding to DataGridComboBoxColumn from collection 2010-02-08

    Trying to bind to a collection in WPF, I got the following to work: XAML: <toolkit:DataGrid Name="dgPeoples"/> CS: namespace DataGrid { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1

  • Trouble binding SelectedItem in ViewModel - MVVM Light Silverlight 4 2011-01-25

    I am using SL4 with MVVM-Light Toolkit. I'm not sure what's going on here. I can't seem to find anything on the web that resolves this issue.. I have a user control that I incorporate into my MainPage.xaml using standard xmlns:local="clr-namespace:Wo

  • Bind a grid to an anonymous LINQ result, then commit changes to DB? 2011-03-04

    I've been looking into how best to do this and wisdom would be appreciated. For read only purposes, I've been happily using LINQ and binding it to a grid. For editing purposes, I've used the LinqDataSource control, enabled the Edit/Delete operations

  • How can I bind and sort a collection 2011-04-07

    If I have an unsorted collection, is there an easy way to bind and sort it. I would like to do it in XAML (no Linq, no C#) If my DataContext has a property, say, MyItems, it is easy to bind against it: <ListBox ItemsSource={Binding MyItems}/> H

  • data binding to grid with unknown number of columns 2011-04-11

    How do I bind to a WPF grid with an unknown number of columns? I have a class that can return the number of columns and column names, etc. as well as the items that will get bound to each row. Basically, I want to do what the DataTable can do without

  • How to bind a Grid in WPF when using MVC? 2011-08-08

    I know a way to do MVC binding of one string to one TextBox. That's how it can be done: C#: namespace WpfApplication4 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = Model; } public ModelClass M

  • Binding two Flex array collection to Flex one array collection 2011-10-10

    In my flex application im using two datagrid first datgrid is for items collections second is for bank details. if i click one row in first datagrid (which has the items collections)...a unique code is taken from the grid(which is primary key). then,

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.082 (s). 11 q(s)