Group rows in DataGridView

后端 未结 3 1588
独厮守ぢ
独厮守ぢ 2020-12-06 12:56

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 implemen

3条回答
  •  情歌与酒
    2020-12-06 13:14

    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.

    enter image description here

    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;
      }
    }
    

提交回复
热议问题