cxgrid能不能横向合并单元格,各位帮忙一下!  如把A1.B1两个单元格合并

解决方案 »

  1.   

    1)cxGridDBTableViewColumn1.Options.CellMerging:=true
      2)编写代码
    procedure TfrmYFCOPR01A.cxGrid1DBBandedTableView1PAB01CompareRowValuesForCellMerging(
      Sender: TcxGridColumn; ARow1: TcxGridDataRow;
      AProperties1: TcxCustomEditProperties; const AValue1: Variant;
      ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties;
      const AValue2: Variant; var AAreEqual: Boolean);
    begin
      inherited;
      if (ARow1.Values[0] = ARow2.Values[0]) AND (ARow1.Values[1] = ARow2.Values[1]) then
        AAreEqual := True
      else
      AAreEqual := False;
    end;
      

  2.   

    void __fastcall TSheetOutput::MultiTitleMerge(TdxSpreadSheetTableView * AView, TRect ARect)
    {
    do
    {
    if (ARect.Top < ARect.Bottom)
    {
    String S = AView->CreateCell(ARect.Top, ARect.Left)->AsString;
    if (AView->CreateCell(ARect.Top + 1, ARect.Left)->IsEmpty)
    {   //  如果下一行是空, 则将该列合并到底行
    AView->MergedCells->Add(TRect(ARect.Left, ARect.Top, ARect.Left, ARect.Bottom));
    }
    else if (ARect.Left < ARect.Right) //  如果是多列
    {
    int LCount = 0;  //  合并列数 while (ARect.Left + LCount < ARect.Right)
    if (SameText(S, AView->CreateCell(ARect.Top, ARect.Left + LCount + 1)->AsString))
       LCount++;
    else break; if (LCount)
    {
    AView->ClearCells(TRect(ARect.Left + 1,
    ARect.Top, ARect.Left + LCount, ARect.Top), false, false); AView->MergedCells->Add(TRect(ARect.Left, ARect.Top,
    ARect.Left + LCount, ARect.Top)); if (ARect.Top < ARect.Bottom)
    MultiTitleMerge(AView, TRect(ARect.Left,
    ARect.Top+1, ARect.Left + LCount, ARect.Bottom));
    ARect.Left += LCount;
    }
    else MultiTitleMerge(AView, TRect(ARect.Left,
    ARect.Top + 1, ARect.Left, ARect.Bottom));
    }
    else MultiTitleMerge(AView, TRect(ARect.Left,
    ARect.Top + 1, ARect.Left, ARect.Bottom));
    }
    ARect.Left++;
    } while (ARect.Left <= ARect.Right);
    }
    这个是 BCB 的, 有纵向和横向的