DataGridView中的组行 [英] Group rows in DataGridView

查看:911
本文介绍了DataGridView中的组行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我想组合在Windows窗体上的数据网格视图中具有相同名称的行是我想要实现的图像。是否可以在不使用任何第三方工具的情况下实现。

解决方案

您可以尝试使用MSFlexGrid的MergeCells属性的垂直单元格合并而不是行分组的功能,如本文所述 DataGridView分组在C#/ VB.NET:两个食谱。在这个例子中,属于一个组的行是使用垂直合并的单元而不是使用经典的水平组行来直接连接的。



  protected override void OnCellPainting DataGridViewCellPaintingEventArgs args)
{
base.OnCellPainting(args);

args.AdvancedBorderStyle.Bottom =
DataGridViewAdvancedCellBorderStyle.None;

//忽略列和行标题和第一行
if(args.RowIndex< 1 || args.ColumnIndex< 0)
return;

if(IsRepeatedCellValue(args.RowIndex,args.ColumnIndex))
{
args.AdvancedBorderStyle.Top =
DataGridViewAdvancedCellBorderStyle.None;
}
else
{
args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top;
}
}


hi all i want to group rows which is having same Name in Data Grid View on windows forms below is the image what i want to implement. is it possible to implement below without using any third party tool.

解决方案

You could try using the functionality of MSFlexGrid's MergeCells property of vertical cell merging instead of row grouping as explained in this article DataGridView Grouping in C#/VB.NET: Two Recipes. In this example, rows which belong to a group are joined visually using cells merged vertically - instead of using classical horizontal group rows.

protected override void OnCellPainting(DataGridViewCellPaintingEventArgs args)
{
  base.OnCellPainting(args);

  args.AdvancedBorderStyle.Bottom =
    DataGridViewAdvancedCellBorderStyle.None;

  // Ignore column and row headers and first row
  if (args.RowIndex < 1 || args.ColumnIndex < 0)
    return;

  if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex))
  {
    args.AdvancedBorderStyle.Top =
      DataGridViewAdvancedCellBorderStyle.None;
  }
  else
  {
    args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top;
  }
}

这篇关于DataGridView中的组行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆