如:
得到了一组衣服尺码的数据
52B 53A 54B 52B 53A 54B 52B 54B 52A 52B 53B 54A 45B 46A 54B 52A 56B 如何在datagrid里显示
52B(5)
53A(2)
54B(3)
....
这样,谢谢!

解决方案 »

  1.   

    自己手动在dataTable里分组统计然后把dataTable绑定在dataGrid上
      

  2.   

    最好是用查询语句分组。如果在页面里分组也行,先把这组数据放到ArrayList里,然后用到双重循环可以实现,要自己写这个算法,不难。ArrayList可以直接绑定到DataGrid
      

  3.   

    ~`先把这组数据放到ArrayList里,然后用到双重循环可以实现,要自己写这个算法,不难。ArrayList可以直接绑定到DataGrid
      

  4.   

    竟然被推荐了,LZ和BZ有一腿?
    我写了个给你,用SQL写比较好,不过我这里没装SQL不好写。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    namespace WindowsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                string str = "52B 53A 54B 52B 53A 54B 52B 54B 52A 52B 53B 54A 45B 46A 54B 52A 56B";
                string[] strArr = str.Split(new char[] { ' ' });
                ArrayList al = new ArrayList();
                for(int i=0;i<strArr.Length;i++)
                {
                    al.Add(strArr[i]);
                }
                ArrayList alResult =  new ArrayList();
                for (int i = al.Count-1; i > -1; i--)
                {
                    string strTmp = al[i].ToString();
                    al.RemoveAt(i);
                    int iCount = 1;
                    for(int j=0;j<al.Count;j++)
                    {
                        int index = al.IndexOf(strTmp);
                        if(index<0)
                        {
                            break;
                        }
                        iCount++;
                        al.RemoveAt(index);
                        i--;                }
                    alResult.Add(strTmp+"("+iCount.ToString()+")");
                }
                string strt = string.Empty;
                for(int i=0;i<alResult.Count;i++)
                {
                    strt+="\n\r"+alResult[i].ToString();
                }
                MessageBox.Show(strt);
            }
        }
    }
      

  5.   

    自己解决了
       SQL = "Select A_Class From A_Brand where A_Class in(Select A_Brand_Class from A_Product) group by A_Class order by A_Class desc"
    用聚合函数
      

  6.   

    如果是现成的数据集了,用LINQ吧