goo blog サービス終了のお知らせ 

Visual Studio VB.NET Tips 集

プログラミング集です。
メインはVisual Basic .NET でございます。

DataGridでセルを結合できるコンポーネントとサンプルソース

2011-01-27 20:12:28 | 日記

MSFlexGridのようにセルを結合できるコンポーネントの紹介

ダウンロードはこちらで公開されています⇒Vector(ベクター) 1、結合はこんな感じになります。


2、複数のセル結合は表を作るのに最適


ダウンロードはこちらで公開されています⇒Vector(ベクター)

'初期化
        Me.DataGridViewForMerge1.MergeCellDataList.Clear()
        '==================================
        '詳細設定サンプル
        '==================================
        '----------------------------------
        'Rowヘッダー作成
        '----------------------------------
        For rowIndex As Integer = 0 To 5
            Me.DataGridViewForMerge1.Rows(rowIndex).Cells(0).Value = "予定" & rowIndex.ToString("000")
            Me.DataGridViewForMerge1.Rows(rowIndex).Cells(0).Style.BackColor = Color.Gray
        Next

        '-----------------------------------
        'Colヘッダー作成
        '-----------------------------------
        For colIndex As Integer = 1 To 31
            Me.DataGridViewForMerge1.Columns(colIndex).HeaderText = colIndex.ToString("000")
            Me.DataGridViewForMerge1.Columns(colIndex).Width = 50
        Next

        '-----------------------------------
        '結合処理
        '-----------------------------------
        '結合クラス作成
        Dim mergeCellClass As MergeCellData
        mergeCellClass = New MergeCellData
        '開始行
        mergeCellClass.StartRow = 0
        '開始列
        mergeCellClass.StartCol = 1
        '終了行
        mergeCellClass.EndRow = 0
        '終了列
        mergeCellClass.EndCol = 3
        '色指定
        mergeCellClass.BackColor = Color.Red
        '登録
        Me.DataGridViewForMerge1.MergeCellDataList.Add(mergeCellClass)

        '描画する
        Me.DataGridViewForMerge1.Refresh()