C# 合并单元格 JS的 也可以!
解决方案 »
- 关于FTP批量下载的问题续
- 为什么我找不到contextmenu的menuitem属性啊?
- C/S程序,服务器端如何记录客户端登陆时的计算机名、IP地址..???
- span标记中title的值有两个 怎么连接呢
- winform编译生成DLL,嵌入IM频道页?
- 请教,如何保存数据?
- 【dataGrid的CaptionVisible=true问题】怎么让datagrid的Caption隐藏
- 用过OWC的SpreadSheet的请进,100分给第一个解决问题的朋友
- DataTable to TreeView
- 关于消息队列中的消息访问问题
- 用Winfrom怎么调用后台的JSON
- 求c#中树的应用的实例
///GridView 单元格合并方法
/// </summary>
/// <param name="gv">要合并的GridView</param>
/// <param name="cellNum"></param>
public static void GetGridViewGroupRows(GridView gv, int cellNum)
{ int i = 0, rowSpanNum = 1; while (i < gv.Rows.Count - 1)
{
GridViewRow gvr = gv.Rows[i]; for (++i; i < gv.Rows.Count; i++)
{
GridViewRow gvrNext = gv.Rows[i]; if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
} else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
} if (i == gv.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}2.合并列/// <summary>
/// 合并单元格
/// </summary>
/// <param name="gridView"></param>
/// <param name="CompareCells">比较基准列</param>
/// <param name="MergeCells">合并列</param>
public static void MergeCells(GridView gridView, int[] CompareCells, int[] MergeCells)
{
int intSpan = 0;
int j = 0;
string[] curCellsValue = new string[CompareCells.Length];
string[] nextCellsValue = new string[CompareCells.Length];
for (int i = 0; i < gridView.Rows.Count; i++)
{
intSpan = 1;
j = 0;
for (int k = 0; k < CompareCells.Length; k++)
{
curCellsValue[k] = gridView.Rows[i].Cells[CompareCells[k]].Text;
} for (j = i + 1; j < gridView.Rows.Count; j++)
{
for (int k = 0; k < CompareCells.Length; k++)
{
nextCellsValue[k] = gridView.Rows[j].Cells[CompareCells[k]].Text;
} if (IsEqual(curCellsValue, nextCellsValue))
{
intSpan++;
for (int k = 0; k < MergeCells.Length; k++)
{
gridView.Rows[i].Cells[MergeCells[k]].RowSpan = intSpan;
gridView.Rows[j].Cells[MergeCells[k]].Visible = false;
}
}
else
break;
}
i = j - 1;
}
}3. /// <summary>
/// 比较两个数组元素是否相等
/// </summary>
/// <param name="arraySource"></param>
/// <param name="arrayTarget"></param>
/// <returns></returns>
protected static bool IsEqual(string[] arraySource, string[] arrayTarget)
{
int arrayLen = arraySource.Length;
bool isEqual = true;
for (int i = 0; i < arrayLen; i++)
{
if (string.Compare(arraySource[i], arrayTarget[i], true) == 0)
continue;
else
return false;
}
return isEqual;
}