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

Horizontal Binding

3 Answers 117 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 29 Jul 2011, 07:42 PM

I have a senario similar to this:

class CarManufacture
{
    String Name { get; set; }
    String Description { get; set; }
   List<Model> CarModels { get; set; }
   List<Model> TruckModels { get; set; }
}
 
class Model
{
   string ModelName { get; set; }
}


The list of Manufactures will be the datasource, and it won't be a fixed count.  What I want to do is show the Manufactures horizontally, and below them, the lists of cars and trucks.  So something like this:

                Chevrolet            Ford                Nissan
                [Description]        [Discription]    [Description]

Cars        Malibu                Mustang           Altima
                Impala                Fusion              Maxima
                Camaro                                       Versa

Trucks     Colorado            F150                Titan
                Silverado            F250
            

How can I accomplish this?  I'm trying with a CrossTab, but can't quite figure it out.  Are there any examples of something like this?



3 Answers, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 29 Jul 2011, 07:54 PM
... would it be easier if my datasource were a list of objects like this:
class Model
{
   string ManufactureName { get; set; }  // ex. "Chevrolet"
   string ModelName { get; set; }  // ex. "Malibu"
   string ModelType { get; set; }  // ex. "Car" or "Truck"
}

0
Justin Lee
Top achievements
Rank 1
answered on 01 Aug 2011, 02:39 PM
I have started building the report by manually building a Table in code.  (if there is a better way to do this report, ignore this question, and give the better solution for the report)

I have constructed the rows and columns successfully, and now I am adding a List reporting object to each cell.  I add a TextBox to the List object, and then bind the List to a datasource (an IEnumerable)

// assume rows and columns are constructed, and row/column headers are set
int
rowIndex = 1;
int columnIndex = 1;
foreach (Manufacturer manufacturer in allManufactures)
{
   rowIndex = 1;
   foreach (ModelType modelType in allModelTypes) // ex. Car, Truck, SUV
   {
       Telerik.Reporting.List list = new List();
       list.Width = new Unit(2d, UnitType.Inch);
                     
       list.Body.Columns.Add(new TableBodyColumn(new Unit(2d, UnitType.Inch)));
       list.Body.Rows.Add(new TableBodyRow(new Unit(0.17, UnitType.Inch)));
 
       list.ColumnGroups.Add(new TableGroup());
       TableGroup listRowGroup = new TableGroup();
       listRowGroup.Groupings.Add(new Telerik.Reporting.Data.Grouping(""));
       list.RowGroups.Add(listRowGroup);
 
       txtbx = new Telerik.Reporting.TextBox()
       {
           Value = "=Fields.ModelName",
           Width = new Unit(2d, UnitType.Inch),
           Height = new Unit(0.17d, UnitType.Inch)
       };
       panel = new Telerik.Reporting.Panel();
       panel.Size = new SizeU(new Unit(2d, UnitType.Inch), new Unit(0.17, Inch));
       panel.Items.Add(txtbx);
       list.Body.SetCellContent(0, 0, panel);
       list.Items.Add(panel);
          
       // Bind List
       list.DataSource = manufacturer.AllModels.Where(x => x.TypeOfModelID == t.ID);
 
       table1.Body.SetCellContent(rowIndex, columnIndex, list);
       table1.Items.Add(list);
 
       rowIndex++;
 
   }
         columnIndex++;
}

A list gets added to each cell, but the databinding doesn't work right - the cells are blank.  If I change the text of the textbox to be "Test", then 1 textbox gets shown in each cell (with "Test" as the text).  But the list of models for each cell is more than 1.

What am I doing wrong?  Can I not do it this way?

Thanks,
Justin




0
Justin Lee
Top achievements
Rank 1
answered on 02 Aug 2011, 05:42 PM
I got this report to work, so I don't need an answer. The code isn't pretty, but it works.
Tags
General Discussions
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Share this question
or