热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->net 
站内搜索:
DataGrid用法:合并内容相同的单元格
作者:生活碎片 来源:blog 整理日期:2007-9-28

**//// <summary>
        /// DataGrid中相同单元格的合并
        /// </summary>
        public void SpanGrid()
        ...{
            int i;
            int j;
            int intSpan;
            string strTemp;

            for (i = 0; i < DataGrid1.Items.Count;)
            ...{
                intSpan = 1;
               
                strTemp = DataGrid1.Items[i].Cells[0].Text;
               
                //循环判断,判断第一列中,和第一行相同的内容
                for (j = i + 1; j < DataGrid1.Items.Count; j ++)
                ...{
                    if (string.Compare(strTemp, DataGrid1.Items[j].Cells[1].Text) == 0)
                    ...{
                        intSpan += 1;

                        //利用datagrid的RowSpan属性
                        DataGrid1.Items[i].Cells[0].RowSpan = intSpan;

                        //把内容相同单元格隐藏
                        DataGrid1.Items[j].Cells[0].Visible = false;
                    }
                    else
                    ...{
                        break;
                    }                   
                }

                i = j -1;
            }
        }
 

相关文章