I have the following private method in a databound Control, that I am
developing, using the GTK widgets.

My problem is in the "case "System.Decimal":" section of the code. I am
unable to find a way of setting up to pass Decimal values to the Column
in question, so that I can later sort the Column on the numerical
values. instead I am forced to pass the decimal values as Strings, which
of course then forces a String sort. The fact that I am able to pass
integer values see the "case "System.Int32":" section of the code, and
then have the TreeView widget sort on the numerical values, leads me to
assume that I should be able to pass the Decimal values. Is there a way
to do this? What am I missing?

Regards

Tracy Barlow

private Gtk.ListStore BuildListBox()
{
        Gtk.CellRendererText textCell = null;
        Gtk.CellRendererToggle toggleCell = null;
        Gtk.CellRendererPixbuf pixbufCell = null;
        
        Gtk.TreeViewColumn col = null;
        System.Type[] ColumnTypes = null;
        Gtk.ListStore store = null;
        object[] dataValues = null;
                        
        IEnumerable source = DataSourceHelper.GetResolvedDataSource(dataSource,
_dataMember);
        
        int row = 0;
        foreach (object di in source)
        {
                PropertyDescriptorCollection dic = 
TypeDescriptor.GetProperties(di);
                dataValues = new System.Object[dic.Count];
                
                int column = 0;
                if (row == 0)
                {
                        ColumnTypes = new System.Type[dic.Count];
                        foreach (PropertyDescriptor dpd in dic)
                        {
                                Type propType = dpd.PropertyType;

                                
                                System.ComponentModel.TypeConverter converter =
System.ComponentModel.TypeDescriptor.GetConverter(propType);
                                if (( converter != null) && 
converter.CanConvertTo(typeof(string)))
                                {
                                        
                                        col = new Gtk.TreeViewColumn();
                                        col.Clicked += on_Column_Header_Clicked;
                                        col.Title = dpd.DisplayName;
                                        
                                        switch (propType.ToString())
                                        {
                                                case "System.String":
                                                        textCell = new 
CellRendererText();
                                                        textCell.Editable = 
true;
                                                        textCell.Edited += 
on_Cell_Edited;                      
                                                        col.PackStart(textCell, 
true);
                                                        ColumnTypes[column] = 
typeof(string);
                                                        
col.AddAttribute(textCell, "text", column);
                                                        dataValues[column] = 
dpd.GetValue(di);  
                                                        break;
                                                case "System.Int32":
                                                        textCell = new 
CellRendererText();
                                                        textCell.Editable = 
true;
                                                        textCell.Edited += 
on_Cell_Edited;                      
                                                        col.PackStart(textCell, 
true);
                                                        ColumnTypes[column] = 
typeof(int);
                                                        
col.AddAttribute(textCell, "text", column);
                                                        dataValues[column] = 
dpd.GetValue(di);  
                                                        break;
                                                case "System.Decimal":
                                                        textCell = new 
CellRendererText();
                                                        textCell.Editable = 
true;
                                                        textCell.Edited += 
on_Cell_Edited;                      
                                                        col.PackStart(textCell, 
true);
                                                        ColumnTypes[column] = 
typeof(string);
                                                        
col.AddAttribute(textCell, "text", column);
                                                        dataValues[column] = 
dpd.GetValue(di).ToString();       
                                                        break;
                                                case "System.SByte":
                                                        toggleCell = new 
CellRendererToggle();
                                                        toggleCell.Activatable 
= true;
                                                        toggleCell.Toggled += 
on_Cell_Activated;                        
                                                        
col.PackStart(toggleCell, true);
                                                        ColumnTypes[column] = 
typeof(bool);
                                                        
col.AddAttribute(toggleCell, "active", column);
                                                        dataValues[column] = 
((SByte)dpd.GetValue(di) == 1);    
                                                        break;
                                        }
                                        
                                        col.SortColumnId = column;
                                        _listBox.AppendColumn(col);
                                        
                                }
                                        
                                column ++;
                        }

                        store = new ListStore (ColumnTypes); 
                }
                else
                {
                        foreach (PropertyDescriptor dpd in dic)
                        {
                                Type propType = dpd.PropertyType;
                                
                                switch (propType.ToString())
                                {
                                        case "System.String":
                                                dataValues[column] = 
dpd.GetValue(di);  
                                                break;
                                        case "System.Int32":
                                                dataValues[column] = 
dpd.GetValue(di);  
                                                break;
                                        case "System.Decimal":
                                                dataValues[column] = 
dpd.GetValue(di).ToString();       
                                                break;
                                        case "System.SByte":
                                                dataValues[column] = 
((SByte)dpd.GetValue(di) == 1);    
                                                break;
                                }
                                column++;
                        }
                }
        
                store.AppendValues(dataValues);
                row++;
        }

return store;   
}

_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to