我想合并相同内容的单元格,如何写?

解决方案 »

  1.   


    Private datPrimaryRS As ADODB.Recordset
    ' 打开连接
      sSQL = "select dw_bm,dw_mc from dw_table where dw_mc like'%" & Text1.Text & "%' order by dw_bm"
      sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
      Set dfwConn = New Connection
      dfwConn.Open sConnect  ' 使用提供的集合创建 recordset
      Set datPrimaryRS = New Recordset
      datPrimaryRS.CursorLocation = adUseClient
      datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
      Set MSHFlexGrid1.DataSource = datPrimaryRS
      
        With MSHFlexGrid1
           Select Case Combo1.ListIndex
               Case 0
                   .FormatString = "单位编码|单位名称"
                   .Redraw = False
                   ' 设置网格列宽度
                  .ColWidth(0) = 1000
                  .ColWidth(1) = 3000
               
           End Select
               
           ' 设置网格列合并和排序
           For i = 0 To .Cols - 1
               .MergeCol(i) = True
           Next i
        
           .Sort = flexSortGenericAscending
        
           ' 设置网格样式
           .AllowBigSelection = True
           .FillStyle = flexFillRepeat
        
           ' 将标头作成粗体
           .Row = 0
           .Col = 0
           .RowSel = .FixedRows - 1
           .ColSel = .Cols - 1
           .CellFontBold = True
        
           ' 隔列变灰
           For i = .FixedCols To .Cols() - 1 Step 2
               .Col = i
               .Row = .FixedRows
               .RowSel = .Rows - 1
               .CellBackColor = &HC0C0C0   ' 浅灰
           Next i
        
           .AllowBigSelection = False
           .FillStyle = flexFillSingle
           .Redraw = True
        
        End With
      datPrimaryRS.Close
      Set datPrimaryRS = Nothing