Author: pedro
Date: 2007-03-07 10:50:32 -0500 (Wed, 07 Mar 2007)
New Revision: 73889

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
Log:
2007-03-07  Pedro Mart?\195?\173nez Juli?\195?\161  <[EMAIL PROTECTED]>

        * DataGridView.cs: Add rows when DataSource is System.Data.DataView
        and a new row is added to it.



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-07 15:41:51 UTC (rev 73888)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-07 15:50:32 UTC (rev 73889)
@@ -1,5 +1,10 @@
 2007-03-07  Pedro Martínez Juliá  <[EMAIL PROTECTED]>
 
+       * DataGridView.cs: Add rows when DataSource is System.Data.DataView
+       and a new row is added to it.
+
+2007-03-07  Pedro Martínez Juliá  <[EMAIL PROTECTED]>
+
        * DataGridView.cs: Add columns when DataSource is en empty list but
        is a System.Data.DataView (from a System.Data.DataTable).
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs  
2007-03-07 15:41:51 UTC (rev 73888)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs  
2007-03-07 15:50:32 UTC (rev 73889)
@@ -592,6 +592,9 @@
                                        if (!(value is IList) && !(value is 
IListSource) && !(value is IBindingList) && !(value is IBindingListView)) {
                                                throw new 
NotSupportedException("Type cant be binded.");
                                        }
+                                       if (dataSource != null && dataSource is 
DataView) {
+                                               (dataSource as 
DataView).ListChanged -= OnListChanged;
+                                       }
                                        dataSource = value;
                                        OnDataSourceChanged(EventArgs.Empty);
                                        // DataBinding
@@ -3067,7 +3070,7 @@
 
                protected override void OnPaint (PaintEventArgs e) {
                        base.OnPaint(e);
-                       //Console.WriteLine(e.ClipRectangle);
+                       Console.WriteLine("DataGridView.OnPaint-ClipRectangle: 
{0};", e.ClipRectangle);
                        Rectangle bounds = ClientRectangle; //e.ClipRectangle;
                        e.Graphics.FillRectangle(new 
SolidBrush(backgroundColor), bounds);
                        Pen pen = new Pen(gridColor);
@@ -3167,7 +3170,7 @@
                                if (horizontalScrollBar.Visible && (gridHeight 
+ horizontalScrollBar.Height) > Size.Height) {
                                        verticalScrollBar.Visible = true;
                                }
-                               if (verticalScrollBar.Visible && (gridWidth + 
horizontalScrollBar.Width) > Size.Width) {
+                               if (verticalScrollBar.Visible && (gridWidth + 
verticalScrollBar.Width) > Size.Width) {
                                        horizontalScrollBar.Visible = true;
                                }
                                if (horizontalScrollBar.Visible) {
@@ -3654,7 +3657,8 @@
 
                private void BindIList (IList list) {
                        if (list is DataView) {
-                               DataTable table = (list as DataView).Table;
+                               DataView dataView = (DataView) list;
+                               DataTable table = dataView.Table;
                                DataGridViewCell template = new 
DataGridViewTextBoxCell();
                                foreach (DataColumn dataColumn in 
table.Columns) {
                                        DataGridViewColumn col = new 
DataGridViewColumn(template);
@@ -3662,6 +3666,7 @@
                                        col.ValueType = dataColumn.DataType;
                                        columns.Add(col);
                                }
+                               dataView.ListChanged += OnListChanged;
                        }
                        else if (list.Count > 0) {
                                DataGridViewCell template = new 
DataGridViewTextBoxCell();
@@ -3696,6 +3701,24 @@
                        BindIList(list);
                }
 
+               private void OnListChanged (object sender, ListChangedEventArgs 
args) {
+                       if (args.OldIndex >= 0) {
+                       }
+                       if (args.NewIndex >= 0) {
+                               object element = (sender as 
DataView)[args.NewIndex];
+                               DataGridViewRow row = new DataGridViewRow();
+                               rows.InternalAdd(row);
+                               PropertyDescriptorCollection properties = 
TypeDescriptor.GetProperties(element);
+                               foreach (PropertyDescriptor property in 
properties) {
+                                       DataGridViewTextBoxCell cell = new 
DataGridViewTextBoxCell();
+                                       cell.Value = property.GetValue(element);
+                                       cell.ValueType = property.PropertyType;
+                                       row.Cells.Add(cell);
+                               }
+                               Invalidate();
+                       }
+               }
+
                public sealed class HitTestInfo {
 
                        public static readonly HitTestInfo Nowhere = new 
HitTestInfo(-1, -1, -1, -1, DataGridViewHitTestType.None);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to