[Mono-bugs] [Bug 337470] DataGridView: string[] is not convertible to string

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Nov 3 11:23:51 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=337470#c1





--- Comment #1 from Dimitar Dobrev <dpldobrev at yahoo.com>  2007-11-03 09:23:49 MST ---
Created an attachment (id=181925)
 --> (https://bugzilla.novell.com/attachment.cgi?id=181925)
Contains a test case for the proposed patch

I am sorry the test case doesn't work but the reason is this: to test the patch
I needed to use the changed DataGridView and I had no intention to recomplie
the whole Mono. That's why I sopied the changed DataGridView and put it in a
namespace called "Test" and then tried Test.DataGridView dgv = new
Test.DataGridView (to use the changed DataGridView because). I got an error
that the complier cannot find the namespace Test, I guess it's a compiler bug.
Anyway, I suggest the following solution - the method DataGridView.BindIList
should be changed from:

private void BindIList (IList list) {
                        if (list is DataView) {
                                DataView dataView = (DataView) list;
                                DataTable table = dataView.Table;
                                DataGridViewCell template = new
DataGridViewTextBoxCell();
                                foreach (DataColumn dataColumn in
table.Columns) {
                                        DataGridViewColumn col = new
DataGridViewColumn(template);
                                        col.Name = dataColumn.ColumnName;
                                        col.ValueType = dataColumn.DataType;
                                        columns.Add(col);
                                }
                                dataView.ListChanged += OnListChanged;
                        }
                        else if (list.Count > 0) {
                                DataGridViewCell template = new
DataGridViewTextBoxCell();
                                foreach (PropertyDescriptor property in
TypeDescriptor.GetProperties(list[0])) {
                                        DataGridViewColumn col = new
DataGridViewColumn(template);
                                        col.Name = property.DisplayName;
                                        columns.Add(col);
                                }
                        }
                        foreach (object element in list) {
                                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);
                                }
                        }
                }

to:

private void BindIList (IList list) {
                        if (list is DataView) {
                                DataView dataView = (DataView) list;
                                DataTable table = dataView.Table;
                                DataGridViewCell template = new
DataGridViewTextBoxCell();
                                foreach (DataColumn dataColumn in
table.Columns) {
                                        DataGridViewColumn col = new
DataGridViewColumn(template);
                                        col.Name = dataColumn.ColumnName;
                                        col.ValueType = dataColumn.DataType;
                                        columns.Add(col);
                                }
                                dataView.ListChanged += OnListChanged;
                        }
                        else if (list.Count > 0) {
                                DataGridViewCell template = new
DataGridViewTextBoxCell();
                                foreach (PropertyDescriptor property in
TypeDescriptor.GetProperties(list[0])) {
                                        DataGridViewColumn col = new
DataGridViewColumn(template);
                                        col.Name = property.DisplayName;
                                        columns.Add(col);
                                }
                        }
                        foreach (object element in list) {
                                DataGridViewRow row = new DataGridViewRow();
                                rows.InternalAdd(row);
                                PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(element);
                                foreach (PropertyDescriptor property in
properties) {
                                        Type cellType = property.PropertyType;
                                        MessageBox.Show("Checking type.");
                                        bool is_cell_type_IConvertible = false;
                                        foreach (Type type in
cellType.GetInterfaces()){
                                                if (type ==
System.IConvertible){
                                                       
is_cell_type_IConvertible = true;
                                                        break;
                                                }
                                        }
                                        if (!is_cell_type_IConvertible){
                                                continue;
                                        }
                                        DataGridViewTextBoxCell cell = new
DataGridViewTextBoxCell();
                                        cell.Value =
property.GetValue(element);
                                        cell.ValueType = cellType;
                                        row.Cells.Add(cell);
                                }
                        }
                }

The type of each property is checked if it is IConvertible and if not, no
column is created. That is the behaviour of MS's grid.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list