Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

How to display the values in a Grid from an arraylist

Hi, I'm having an arraylist and in the arraylist I have values for 24 hours in a day. For each Unit(which is a primary field) I have multiple column values for each hour. When I fill the datable and to dataset
and bind the dataset I get displayed vertically instead of horizontally how to flip the values and display it.

Here is how it looks like:

Hour Ending1
       Unit1,colum1,column2 values
Hour Ending 2
      Unit1,column1,column2 values
...SO on
Hour Ending 24
     Unit1,column1,column2 values.

Here is how I want:

Hour Ending1                                Hour Ending2    
Unit1,column1,column2 values        Unit1,column1,column2 values and
So on.. Hour Ending24.

comments:I'm currently doing this from the array list:

 ArrayList umarray = m_clsum.Build1(um); //<--I get arraylist from class.

                //Test
                //System.Data.DataSet ds = new System.Data.DataSet("umarray");
                             DataSet ds = new DataSet();
             
                Type myType = umarray[0].GetType();
                System.Reflection.PropertyInfo[] api = myType.GetProperties();

                foreach (System.Reflection.PropertyInfo pi in api)
                    dt.Columns.Add(pi.Name);
                System.Data.DataRow dr = null;
             
                foreach (object obj in umarray)
                {
                    dr = dt.NewRow();
                    foreach (System.Data.DataColumn myColumn in dt.Columns)
                       dr[myColumn.Caption] = myType.GetProperty(myColumn.Caption).GetValue(obj, null);
                    dt.Rows.Add(dr);
               
                }
               
                ds.Tables.Add(dt);
               
           
                int i;
                int hour = DateTime.Now.Hour;
                           
                for (i = 0; i <= (ds.Tables[0].Columns.Count - 1); i = i + 1)
                    ds.Tables[0].Columns[i].ColumnName = ds.Tables[0].Columns[i].ColumnName + hour;
                string colname;
                colname = ds.Tables[0].Columns[15].ColumnName;

                //ds.ReadXml("C:/temp/umarraytest.xml");
                ds.WriteXml("c:/temp/umarray.xml");

Thanks VM
0
vmandem
Asked:
vmandem
1 Solution
 
Bob LearnedCommented:
Recreate the DataTable with the rows as columns.

Bob
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now