uniek's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
2 (0 per day)
Joined:
01-October 12
Profile Views:
131
Last Active:
User is offline Oct 02 2012 04:11 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   uniek has not set their status

Posts I've Made

  1. In Topic: C# make column values as header column and group the result

    Posted 1 Oct 2012

    I have tried with this code:

    var result = new DataTable();
                result.Columns.Add("ID", typeof(Int32));
                result.Columns.Add("Name", typeof(String));
                result.Columns.Add("Produkt", typeof(String));
                result.Columns.Add("Comment", typeof(String));
    
                result.Columns.AddRange(
                    (from c in
                         (from r in table.AsEnumerable()
                          where !r.IsNull("Attribute") && !string.IsNullOrEmpty(r.Field<string>("Attribute"))
                          select r.Field<string>("Attribute")).Distinct()
                     select new DataColumn(c, typeof(bool))).ToArray()
                );
    
                foreach (var r in results)
                {
                    var productIndex = result.Columns.IndexOf(r.Attribute);
                    var vals = new List<object>() { r.ID, r.Name, r.Produkt, r.Comment };
                    for (int i = 4; i < result.Columns.Count; i++)
                    {
    
                        if (i == productIndex)
                        {
                            vals.Add(true);
    
                        }
                        else
                        {
                            vals.Add(false);
                        }
                    }
    
                    result.LoadDataRow(vals.ToArray(), true);
                    dataGridView2.DataSource = results.ToList();
    
                }
    


    But it doesnt work like i want to. It shows a tables with Mike in 2 lines, but i want to show it just in 1 line:

    ID Name Produkt Comment aa cc

    1 Mike AA YY x // Here and
    1 Mike AA YY x // Here should be in one line, see 1)
    2 Steve BB YY x
    3 None XX x
    4 Hube DD

    [quote name='uniek' date='01 October 2012 - 07:22 AM' timestamp='1349101375' post='1713031']
    I have tried with this code:

    var result = new DataTable();
                result.Columns.Add("ID", typeof(Int32));
                result.Columns.Add("Name", typeof(String));
                result.Columns.Add("Produkt", typeof(String));
                result.Columns.Add("Comment", typeof(String));
    
                result.Columns.AddRange(
                    (from c in
                         (from r in table.AsEnumerable()
                          where !r.IsNull("Attribute") && !string.IsNullOrEmpty(r.Field<string>("Attribute"))
                          select r.Field<string>("Attribute")).Distinct()
                     select new DataColumn(c, typeof(bool))).ToArray()
                );
    
                foreach (var r in results)
                {
                    var productIndex = result.Columns.IndexOf(r.Attribute);
                    var vals = new List<object>() { r.ID, r.Name, r.Produkt, r.Comment };
                    for (int i = 4; i < result.Columns.Count; i++)
                    {
    
                        if (i == productIndex)
                        {
                            vals.Add(true);
    
                        }
                        else
                        {
                            vals.Add(false);
                        }
                    }
    
                    result.LoadDataRow(vals.ToArray(), true);
                    dataGridView2.DataSource = results.ToList();
    
                }
    


    But it doesnt work like i want to. It shows a tables with Mike in 2 lines, but i want to show it just in 1 line:
    ID    Name    Produkt   Comment   aa    cc  
    
    1     Mike    AA        YY        x          // Here and
    1     Mike    AA        YY              x    // Here should be in one line, see 1)
    2     Steve   BB        YY        x  
    3     None              XX              x  
    4     Hube    DD
    
    


    But it doesnt work like i want to. It shows a tables with Mike in 2 lines, but i want to show it just in 1 line:
    ID    Name    Produkt   Comment   aa    cc  
    
    1     Mike    AA        YY        x          // Here and
    1     Mike    AA        YY              x    // Here should be in one line, see 1)
    2     Steve   BB        YY        x  
    3     None              XX              x  
    4     Hube    DD
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

uniek hasn't added any friends yet.

Comments

uniek has no profile comments yet. Why not say hello?