diff options
author | Ivan Zlatev <ivan@ivanz.com> | 2009-08-07 22:24:25 +0400 |
---|---|---|
committer | Ivan Zlatev <ivan@ivanz.com> | 2009-08-07 22:24:25 +0400 |
commit | f559c9b1920683df9bf0adf0ef02bbdfd4294602 (patch) | |
tree | 832cc74573a8e89744477bdf262b7ccda5f109a6 /mcs | |
parent | 7a6b057458c1d4a775590292da5b889a06fe3a0e (diff) |
2009-08-07 Ivan N. Zlatev <contact@i-nz.net>
* DataGridView.cs, DataGridViewCell.cs, DataGridViewColumn.cs:
Massive population performance boost. From seconds to ms.
[Fixes bug #528887]
svn path=/trunk/mcs/; revision=139581
Diffstat (limited to 'mcs')
4 files changed, 47 insertions, 28 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index 4dbbf231aaf..b7c2deb05ed 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,9 @@ +2009-08-07 Ivan N. Zlatev <contact@i-nz.net> + + * DataGridView.cs, DataGridViewCell.cs, DataGridViewColumn.cs: + Massive population performance boost. From seconds to ms. + [Fixes bug #528887] + 2009-08-04 Carlos Alberto Cortez <calberto.cortez@gmail.com> * DataGrid.cs: When handling mouse down on a column, don't do any sort diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs index ab9339b666f..9a98c204d53 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs @@ -3792,11 +3792,25 @@ namespace System.Windows.Forms { row.Cells.Add ((DataGridViewCell)e.Column.CellTemplate.Clone ()); } + e.Column.DataColumnIndex = FindDataColumnIndex (e.Column); AutoResizeColumnsInternal (); OnColumnAdded (e); PrepareEditingRow (false, true); } + private int FindDataColumnIndex (DataGridViewColumn column) + { + if (column != null && DataManager != null) { + PropertyDescriptorCollection properties = DataManager.GetItemProperties(); + for (int i = 0; i < properties.Count; i++) { + if (String.Compare (column.DataPropertyName, properties[i].Name, true) == 0) + return i; + } + } + + return -1; + } + protected virtual void OnColumnAdded (DataGridViewColumnEventArgs e) { DataGridViewColumnEventHandler eh = (DataGridViewColumnEventHandler)(Events [ColumnAddedEvent]); @@ -6035,28 +6049,12 @@ namespace System.Windows.Forms { DataGridViewRow row = (DataGridViewRow)RowTemplateFull; rows.AddInternal (row, false); - - PropertyDescriptorCollection properties = TypeDescriptor.GetProperties (element); - foreach (PropertyDescriptor property in properties) { - if (property.PropertyType == typeof (IBindingList)) - continue; - - // We do it this way because there may not be a column - // for every cell, ignore cells with no column - DataGridViewCell cell = row.Cells.GetBoundCell (property.Name); - - if (cell == null) - continue; - - cell.Value = property.GetValue (element); - cell.ValueType = property.PropertyType; - } } private bool IsColumnAlreadyBound (string name) { foreach (DataGridViewColumn col in Columns) - if (col.DataPropertyName == name) + if (String.Compare (col.DataPropertyName, name, true) == 0) return true; return false; @@ -6124,7 +6122,7 @@ namespace System.Windows.Forms { DataGridViewColumn col = CreateColumnByType (property.PropertyType); col.Name = property.DisplayName; - col.DataPropertyName = property.DisplayName; + col.DataPropertyName = property.Name; col.ReadOnly = !DataManager.AllowEdit || property.IsReadOnly; col.SetIsDataBound (true); col.ValueType = property.PropertyType; @@ -6136,11 +6134,10 @@ namespace System.Windows.Forms { } // DataBind both autogenerated and not columns if there is a matching property - foreach (PropertyDescriptor property in DataManager.GetItemProperties()) { - foreach (DataGridViewColumn col in Columns) { - if (col.DataPropertyName == property.Name) - col.SetIsDataBound (true); - } + foreach (DataGridViewColumn column in columns) { + column.DataColumnIndex = FindDataColumnIndex (column); + if (column.DataColumnIndex != -1) + column.SetIsDataBound (true); } foreach (object element in DataManager.List) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCell.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCell.cs index 5c6ffa65e32..1aa7031cb93 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCell.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCell.cs @@ -388,7 +388,16 @@ namespace System.Windows.Forms { [Browsable (false)] public virtual Type ValueType { - get { return valueType; } + get { + if (valueType == null) { + if (DataProperty != null) + valueType = DataProperty.PropertyType; + else if (OwningColumn != null) + valueType = OwningColumn.ValueType; + } + + return valueType; + } set { valueType = value; } } @@ -912,7 +921,7 @@ namespace System.Windows.Forms { protected virtual object GetValue (int rowIndex) { if (DataGridView != null && (RowIndex < 0 || RowIndex >= DataGridView.Rows.Count)) throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values."); - + if (DataProperty != null) return DataProperty.GetValue (OwningRow.DataBoundItem); @@ -927,9 +936,9 @@ namespace System.Windows.Forms { private PropertyDescriptor DataProperty { get { - if (OwningColumn != null && !String.IsNullOrEmpty (OwningColumn.DataPropertyName) && - OwningRow != null && OwningRow.DataBoundItem != null) - return TypeDescriptor.GetProperties (OwningRow.DataBoundItem)[OwningColumn.DataPropertyName]; + if (OwningColumn != null && OwningColumn.DataColumnIndex != -1 && + DataGridView != null && DataGridView.DataManager != null) + return DataGridView.DataManager.GetItemProperties()[OwningColumn.DataColumnIndex]; return null; } } diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs index de61e7ab632..b7b3295acba 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs @@ -57,6 +57,7 @@ namespace System.Windows.Forms { private Type valueType; private bool visible = true; private int width = 100; + private int dataColumnIndex; private bool headerTextSet = false; @@ -68,6 +69,7 @@ namespace System.Windows.Forms { headerCell.SetColumnIndex(Index); headerCell.Value = string.Empty; displayIndex = -1; + dataColumnIndex = -1; dataPropertyName = string.Empty; fillWeight = 100.0F; sortMode = DataGridViewColumnSortMode.NotSortable; @@ -182,6 +184,11 @@ namespace System.Windows.Forms { } } + internal int DataColumnIndex { + get { return dataColumnIndex; } + set { dataColumnIndex = value; } + } + [DefaultValue (0)] public int DividerWidth { get { return dividerWidth; } |