Optimization problem and bug.

Jan 24, 2013 at 12:34 PM
Edited Jan 24, 2013 at 12:40 PM

The component is very slow when the source is a DataView.

I've test is whith a DataView of 25000 lines. when I Select All, after I deselect an element, it hang.

1. I've make optimization in GetDistictValues Method (GetDistictValues class),

I reduce call time from 26 seconds to 5 seconds (~25000 lines)

public List<CheckedListItem> GetDistictValues(DataGrid grid, string columnName)
{
 DateTime d = DateTime.Now;
            if (grid.ItemsSource is DataView)
            {
                var itemSource = grid.ItemsSource as DataView;
                var ditictValues = new List<CheckedListItem>
                                   {
                                       new CheckedListItem
                                           {IsChecked = false, Name = "(Select All)", IsSelectAll = "(Select All)"}
                                   };
                if (itemSource == null)
                    return null;

                DataTable table = itemSource.Table;
                List<string> filteredValues = GetFilteredColumnValues(columnName, itemSource);
                
                DataTable optTable = table.DefaultView.ToTable(true, columnName);
                                
                EnumerableRowCollection<DataRow> collection =  optTable.AsEnumerable();
                foreach (DataRow row in collection.Where(x=>!string.IsNullOrEmpty(Convert.ToString(x[columnName]))))
                    ditictValues.Add(new CheckedListItem { Name = row[columnName], IsChecked = filteredValues.Contains("'" + row[columnName]+ "'") });
                
                foreach (DataRow row in collection.Where(x=>string.IsNullOrEmpty(Convert.ToString(x[columnName]))))
                {
                    ditictValues.Add(new CheckedListItem { Name = row[columnName], IsChecked = filteredValues.Contains("") });
                    break;
                }                
                foreach (DataRow row in collection.Where(x=>x[columnName]==DBNull.Value))
                {
                    ditictValues.Add(new CheckedListItem { Name = DBNull.Value, IsChecked = filteredValues.Contains(DBNull.Value.ToString()) });
                    break;
                }                
                 if (ditictValues.Count(c => c.IsChecked) == ditictValues.Count - 1)
                        ditictValues[0].IsChecked = true;
                    CurrentDistictValues = ditictValues;                
                //test performance
                System.Diagnostics.Trace.WriteLine(string.Format("GetDistictValues : {0}", DateTime.Now.Second - d.Second));
                return ditictValues;
            }
            else
           {...
 

2. I've great number of exceptions when I select all
,I deselect an item, the program hang if collection is
important(25000 lines) , both with a dataview or collection datasource:
When I look to the output in visual studio, I see this exeptions
origine of exceptions : ExtendedDataGrid class, NotifyPropertyChanged(String info) Method,
PropertyChanged(this, new PropertyChangedEventArgs(info)); line.

System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' MultiBindingExpression:target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

System.Windows.Data Error: 40 : BindingExpression path error: 'FirstName' property not found on 'object' ''Object' (HashCode=16700460)'. BindingExpression:Path=FirstName; DataItem='Object' (HashCode=16700460); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

 

Exceptions can be reproduced using the DataGridTestClient project, selecting all items, and deselecting on item.

Any ideas about this exeptions? I've tried to debug, but it dos'nt debug inside PropertyChanged delegate.

Coordinator
Feb 2, 2013 at 1:30 PM
Hi,

Can you please take latest code and try to reproduce with the records mentioned above.
Please post a solution where it fails, I will look into it and fix the issue and I will put you piece of your code too to make it run fast.

Regards,
bpoojary