This is a migrated thread and some comments may be shown as answers.

Dynamic columns with IDictionary<string, object>

1 Answer 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pedro
Top achievements
Rank 1
Pedro asked on 18 May 2011, 07:07 PM

I want to bind a table to a list of objects, each object has a IDictionary.

public ObjectInstance

   public IDictionary<string, object> Dictionary { get; set; }

The source is a IEnumerable of ObjectInstance's, I've tried this with no success:
void table1_ItemDataBinding(object sender, EventArgs e)
    {
        //create two HtmlTextBox items (one for header and one for data) which would be added to the items collection of the table
        Telerik.Reporting.HtmlTextBox textboxGroup;
        Telerik.Reporting.HtmlTextBox textBoxTable;
 
 
        //we do not clear the Rows collection, since we have a details row group and need to create columns only
        this.table1.ColumnGroups.Clear();
        this.table1.Body.Columns.Clear();
        this.table1.Body.Rows.Clear();
        int i = 0;
        this.table1.ColumnHeadersPrintOnEveryPage = true;
        var attributes = _objectInstances.First().ObjectType.Attributes;
        foreach (var attribute in attributes)
        {
            if (string.IsNullOrWhiteSpace(attribute.ColumnName)) continue;
 
 
            var tableGroupColumn = new Telerik.Reporting.TableGroup();
            this.table1.ColumnGroups.Add(tableGroupColumn);
            this.table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));
 
 
            textboxGroup = new Telerik.Reporting.HtmlTextBox();
            textboxGroup.Style.BorderColor.Default = Color.Black;
            textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
            textboxGroup.Value = attribute.ColumnName;
            textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
            tableGroupColumn.ReportItem = textboxGroup;
 
 
            textBoxTable = new Telerik.Reporting.HtmlTextBox();
            textBoxTable.Style.BorderColor.Default = Color.Black;
            textBoxTable.Style.BorderStyle.Default = BorderType.Solid;
            textBoxTable.Value = "=Dictionary[\"" + attribute.ColumnName + "\"]"; //_objectInstances.First()[attribute.ColumnName].ToString();
            textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
            this.table1.Body.SetCellContent(0, i++, textBoxTable);
            this.table1.Items.AddRange(new ReportItemBase[] {textBoxTable, textboxGroup});
        }
 
 
    }

Which is the correct way to bind to a dictionary ?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 25 May 2011, 05:22 PM
Hello Pedro,

The ObjectDataSource support any types that derive from ICollection such as IDictionary to access to Keys and Values properties. However based on the provided information we are not sure about your goal, thus we will appreciate if you elaborate further on your scenario and open a support thread to send us a sample runnable project to examine locally.

Best wishes,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Pedro
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or