sourcegrid合并单元格查询绑定数据

 //int[] array = { 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 0, 2, 2 };

            //int current = array[0];

            //int m = 0;
            //for (int n = 0; n < array.Length; n++)
            //{
            //    //  Console.WriteLine("Array:{0}",array[n]);
            //    if (array[n] == current)
            //    {
            //        m++;
            //    }
            //    else
            //    {
            //        Console.WriteLine("current:{0},count:{1}", current, m);
            //        current = array[n];

            //        m = 1;

            //    }  
            //}
            //Console.WriteLine("current:{0},count:{1}", current, m);

            //var result = from a in array
            //             group a by a into g
            //             select new { g.Key, Num = g.Count() };
            //result.ToList().ForEach(p => Console.WriteLine("元素:{0}有{1}个", p.Key, p.Num));

           
            string SQL = "SELECT TS.[SID],       TS.SNAME,       te.Sex_Descpriton,       TS.Age,       TG.NGrade,       TC.CNAME  FROM   Tb_Cource      tc,       Tb_Grade       tg,       Tb_Studens     ts,       tb_sex         te WHERE  TG.[SID] = TS.[SID]       AND TC.CID = TG.CID       AND te.sex_id = ts.SEX  ";
            DataTable dt_Students = SingleTon<SqlDataAccess>.Instance.getTable(SQL);

            SetGrid(dt_Students);
            CreateGridHeader();


           
            int rowsCount=2;

            string current_columns01 = dt_Students.Rows[0][0].ToString(); //记录第一行第一列数据
            int m01 = 0;
            foreach (DataRow row in dt_Students.Rows)
            {
               
                
                for (int column = 0; column < dt_Students.Columns.Count + 1; column++)
                {
                    if (column == 0) grid1[rowsCount, column] = new SourceGrid.Cells.RowHeader(rowsCount);
                    //行数



                    #region 合并第一列相同的数据
                    else if (column == 1)
                    {

                        if (row[0].ToString() == current_columns01)
                        {
                            m01++;
                        }
                        else
                        {

                            //新建单元格,合并
                            grid1[rowsCount - m01, column] = new SourceGrid.Cells.Cell(current_columns01);
                            grid1[rowsCount - m01, column].RowSpan = m01;

                            current_columns01 = row[column-1].ToString();
                            m01 = 1;
                        }

                    }
                    #endregion
                    else
                    {
                        grid1[rowsCount, column] = new SourceGrid.Cells.Cell(row[column - 1]);

                    }

                    
                }
                rowsCount++;
            }

            //合并最后一条相同的数据(因为是写在ELSE里)
            grid1[rowsCount - m01, 1] = new SourceGrid.Cells.Cell(current_columns01);
            grid1[rowsCount - m01, 1].RowSpan = m01;

          
 
          
        }

        void CreateGridHeader()
        {

            grid1[0, 0] = new SourceGrid.Cells.ColumnHeader("序号");
            grid1[0, 0].RowSpan = 2;

            string[] Header00 = new string[] { "个人资料", "成绩" };
            string[] Header01 = new string[] { "SID","姓名","性别","年龄","分数","课程"};
           
            grid1[0, 1] = new SourceGrid.Cells.ColumnHeader(Header00[0]); 
            grid1[0, 1].ColumnSpan = 4;
            grid1[0, 5] = new SourceGrid.Cells.ColumnHeader(Header00[1]);
            grid1[0, 5].ColumnSpan =2;

            (grid1[0, 5] as SourceGrid.Cells.ColumnHeader).AutomaticSortEnabled = (grid1[0, 1] as SourceGrid.Cells.ColumnHeader).AutomaticSortEnabled = false;
            for (int i = 1; i <= Header01.Length; i++)
            {
                grid1[1, i] = new SourceGrid.Cells.ColumnHeader(Header01[i-1]);
                (grid1[1, i] as SourceGrid.Cells.ColumnHeader).AutomaticSortEnabled = false;
            }

            //SourceGrid.Cells.Header l_00Header = new SourceGrid.Cells.Header(null);
            //SourceGrid.Cells.Header l_01Header = new SourceGrid.Cells.Header(null);
            //grid1[0, 0] = l_00Header;
            //grid1[1, 0] = l_01Header;

            //int i=1;
            //foreach (DataColumn column in dt.Columns)

            //{
            //    grid1[0, i] = new SourceGrid.Cells.ColumnHeader(column.ColumnName);
              
            //    i++;
            //}
           


           




        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值