HASHTABLE issue

May 27, 2009 at 10:29 PM

Hi,

I want to see the values of my hashtable in a dataGrid when the hashtable is modified.

I have no problem with witting "dataGrid1.ItemsSource = _hashtable.Values; " with Xceed DataGrid.

Why the following short code doesn't work?
How can I do the job?

Thanks,
Kamel


using System;
using System.Collections.Generic;
using System.Collections;
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;

namespace DataGridWPF
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private Hashtable _hashtable;

        public Window1()
        {
            InitializeComponent();
            _hashtable = new Hashtable();
            dataGrid1.ItemsSource = _hashtable.Values;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Trade trade = new Trade();
            trade.Date = DateTime.Now;
            trade.Price = 20;

            _hashtable.Add(Guid.NewGuid(), trade);

            dataGrid1.Items.Refresh();
        }

    }

    public class Trade
    {
        public double Price { get; set; }
        public DateTime Date { get; set; }
    }
}