Click here to Skip to main content
15,913,685 members
Home / Discussions / WPF
   

WPF

 
QuestionDataGrid Sort not updating automatically Pin
Bijesh22-Jun-09 19:02
Bijesh22-Jun-09 19:02 
AnswerRe: DataGrid Sort not updating automatically Pin
Mark Salsbery22-Jun-09 19:37
Mark Salsbery22-Jun-09 19:37 
GeneralRe: DataGrid Sort not updating automatically Pin
Bijesh22-Jun-09 19:47
Bijesh22-Jun-09 19:47 
GeneralRe: DataGrid Sort not updating automatically Pin
Mark Salsbery22-Jun-09 19:58
Mark Salsbery22-Jun-09 19:58 
GeneralRe: DataGrid Sort not updating automatically Pin
Bijesh22-Jun-09 20:33
Bijesh22-Jun-09 20:33 
GeneralRe: DataGrid Sort not updating automatically Pin
Mark Salsbery22-Jun-09 22:07
Mark Salsbery22-Jun-09 22:07 
GeneralRe: DataGrid Sort not updating automatically [modified] Pin
Bijesh23-Jun-09 2:33
Bijesh23-Jun-09 2:33 
AnswerRe: DataGrid Sort not updating automatically Pin
Pete O'Hanlon23-Jun-09 3:33
mvePete O'Hanlon23-Jun-09 3:33 
OK - this is odd. I knocked up a quick sample application and sorted on a column - then I started changing the values in the sorted column and it refreshed and changed the sort order in every case. Here's the sample code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace ModelVisualTest
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    private ObservableCollection<Person> _people;
    public Window1()
    {
      InitializeComponent();
    }

    private void BuildModel()
    {
      _people = new ObservableCollection<Person>();
      _people.Add(new Person() { Forename = "Peter", Surname = "O'Hanlon", Age = 30 });
      _people.Add(new Person() { Forename = "Josh", Surname = "Walton", Age = 29 });
      _people.Add(new Person() { Forename = "William", Surname = "Hill", Age = 28 });
      _people.Add(new Person() { Forename = "Joseph", Surname = "Brannagan", Age = 36 });

      dataGrid1.ItemsSource = _people;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      BuildModel();
    }
  }

  public class Person : INotifyPropertyChanged
  {
    private string _forename;
    public string Forename
    {
      get { return _forename; }
      set
      {
        if (_forename != value)
        {
          _forename = value;
          OnChanged("Forename");
        }
      }
    }
    private string _surname;
    public string Surname
    {
      get { return _surname; }
      set
      {
        if (_surname != value)
        {
          _surname = value;
          OnChanged("Surname");
        }
      }
    }
    private int _age;
    public int Age
    {
      get { return _age; }
      set
      {
        if (_age != value)
        {
          _age = value;
          OnChanged("Age");
        }
      }
    }
    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnChanged(string p)
    {
      PropertyChangedEventHandler handler = PropertyChanged;
      if (handler != null)
      {
        handler(this, new PropertyChangedEventArgs(p));
      }
    }
    #endregion
  }
}
The XAML is simply this:
<Window x:Class="ModelVisualTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
    Loaded="Window_Loaded" >
    <Grid>
        <my:DataGrid x:Name="dataGrid1" AutoGenerateColumns="True" />
    </Grid>
</Window>


"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



GeneralRe: DataGrid Sort not updating automatically Pin
Bijesh24-Jun-09 1:57
Bijesh24-Jun-09 1:57 
GeneralRe: DataGrid Sort not updating automatically Pin
Bijesh30-Jun-09 2:42
Bijesh30-Jun-09 2:42 
QuestionWorkflow designer Pin
Bahram.Zarrin22-Jun-09 11:10
Bahram.Zarrin22-Jun-09 11:10 
AnswerRe: Workflow designer Pin
Pete O'Hanlon22-Jun-09 11:19
mvePete O'Hanlon22-Jun-09 11:19 
AnswerRe: Workflow designer Pin
Eslam Afifi22-Jun-09 13:59
Eslam Afifi22-Jun-09 13:59 
QuestionConvert a glyph from a font to a WPF shape. Pin
Lutosław22-Jun-09 6:37
Lutosław22-Jun-09 6:37 
AnswerRe: Convert a glyph from a font to a WPF shape. Pin
Christian Graus22-Jun-09 10:54
protectorChristian Graus22-Jun-09 10:54 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Lutosław22-Jun-09 13:27
Lutosław22-Jun-09 13:27 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Christian Graus22-Jun-09 13:42
protectorChristian Graus22-Jun-09 13:42 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Lutosław22-Jun-09 14:09
Lutosław22-Jun-09 14:09 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Christian Graus22-Jun-09 15:13
protectorChristian Graus22-Jun-09 15:13 
AnswerRe: Convert a glyph from a font to a WPF shape. Pin
Pete O'Hanlon22-Jun-09 11:24
mvePete O'Hanlon22-Jun-09 11:24 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Lutosław22-Jun-09 13:01
Lutosław22-Jun-09 13:01 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Pete O'Hanlon22-Jun-09 22:19
mvePete O'Hanlon22-Jun-09 22:19 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Lutosław24-Jun-09 4:35
Lutosław24-Jun-09 4:35 
GeneralRe: Convert a glyph from a font to a WPF shape. Pin
Pete O'Hanlon24-Jun-09 4:38
mvePete O'Hanlon24-Jun-09 4:38 
QuestionVertical/Horizontal scrollbar for silverlight page Pin
Sunil P V22-Jun-09 6:06
Sunil P V22-Jun-09 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.