在 DataGridView 中对行进行分组 [英] Group rows in DataGridView

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

问题描述

我想对 Windows 窗体上的 DataGridView 中具有相同名称的行进行分组,下面是我想要实现的图像.

I want to group rows which is having same Name in DataGridView on Windows Forms below is the image what I want to implement.

是否可以在不使用任何第三方工具的情况下实现以下功能?

Is it possible to implement below without using any third party tool ?

推荐答案

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

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天全站免登陆