Hang during databinding of large amount of data to WPF DataGrid

Posted by nihi_l_ist on Stack Overflow See other posts from Stack Overflow or by nihi_l_ist
Published on 2010-05-04T13:38:34Z Indexed on 2010/05/04 13:48 UTC
Read the original article Hit count: 221

Filed under:
|
|
|

Im using WPFToolkit datagrid control and do the binding in such way:

<WpfToolkit:DataGrid x:Name="dgGeneral" SelectionMode="Single"
                              SelectionUnit="FullRow"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              CanUserDeleteRows="False" 
                              Grid.Row="1"  ItemsSource="{Binding Path=Conversations}" >


public List<CONVERSATION> Conversations
        {
            get { return conversations; }
            set
            {
                if (conversations != value)
                {
                    conversations = value;
                    NotifyPropertyChanged("Conversations");
                }
            }
        }  

public event PropertyChangedEventHandler PropertyChanged; 

public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

public void GenerateData()
         {
            BackgroundWorker bw = new BackgroundWorker();

            bw.WorkerSupportsCancellation = bw.WorkerReportsProgress = true;
            List<CONVERSATION> list = new List<CONVERSATION>();

            bw.DoWork += delegate { list = RefreshGeneralData(); };

            bw.RunWorkerCompleted += delegate
                                         {
                                             try
                                             {
                                                 Conversations = list;
                                             }
                                             catch (Exception ex)
                                             {
                                                 CustomException.ExceptionLogCustomMessage(ex);
                                             }

                                         };

            bw.RunWorkerAsync();
        }


And than in the main window i call GenerateData() after setting DataCotext of the window to instance of the class, containing GenerateData().

RefreshGeneralData() returns some list of data i want and it returns it fast.
Overall there are near 2000 records and 6 columns(im not posting the code i used during grid's initialization, because i dont think it can be the reason) and the grid hangs for almost 10 secs!

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf