|
|
' ******************************************************
' カラム追加
' ******************************************************
Public Sub AddColumn(ByVal strName As String, ByVal strTitle As String)
Me.Columns.Add(strName, strTitle)
End Sub
' ******************************************************
' カラム追加
' ******************************************************
Public Sub AddColumn(ByVal strName As String, _
ByVal strTitle As String, ByVal nType As lightbox.LboxColumnType)
Dim nIndex As Integer
If nType = lightbox.LboxColumnType.LboxColumnType_CheckBox Then
Dim column As New System.Windows.Forms.DataGridViewCheckBoxColumn
Me.Columns.Add(column)
nIndex = Me.ColumnCount
Me.Columns(nIndex - 1).HeaderText = strTitle
Me.Columns(nIndex - 1).Name = strName
End If
If nType = lightbox.LboxColumnType.LboxColumnType_Button Then
Dim column As New System.Windows.Forms.DataGridViewButtonColumn
column.UseColumnTextForButtonValue = False
column.Text = strName
Me.Columns.Add(column)
nIndex = Me.ColumnCount
Me.Columns(nIndex - 1).HeaderText = strTitle
Me.Columns(nIndex - 1).Name = strName
End If
If nType = lightbox.LboxColumnType.LboxColumnType_Link Then
Dim column As New System.Windows.Forms.DataGridViewLinkColumn
column.UseColumnTextForLinkValue = False
column.Text = strName
Me.Columns.Add(column)
nIndex = Me.ColumnCount
Me.Columns(nIndex - 1).HeaderText = strTitle
Me.Columns(nIndex - 1).Name = strName
End If
End Sub
| |
|
↓AddColumn 用列挙型定数
|
Public Enum LboxColumnType
LboxColumnType_CheckBox = 1
LboxColumnType_Button = 2
LboxColumnType_Link = 3
End Enum
| |
|
|
|
|
' ******************************************************
' 行追加
' ******************************************************
Public Sub AddRow()
nCurrentRow = Me.Rows.Add(1)
End Sub
| |
|
|
|
|
' ******************************************************
' 列幅変更可能設定
' ******************************************************
Public Sub AllowResizeColumn(ByVal flg As Boolean)
If flg Then
Dim width As New Dictionary(Of Integer, Single)
Dim i As Integer = 0
For i = 0 To Me.ColumnCount() - 1
width(i) = Me.Columns(i).Width
Next
Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
For i = 0 To Me.ColumnCount() - 1
Me.Columns(i).Width = width(i)
Next
End If
Me.AllowUserToResizeColumns = flg
End Sub
| |
|
|
|
|
' ******************************************************
' 行幅変更可能設定
' ******************************************************
Public Sub AllowResizeRow(ByVal flg As Boolean)
Me.AllowUserToResizeRows = flg
End Sub
| |
|
|
|
|
' ******************************************************
' 行をすべて削除
' ******************************************************
Public Sub Clear()
Dim count As Integer = Me.Rows.Count
Dim i As Integer
For i = count - 1 To 0 Step -1
Me.Rows.RemoveAt(i)
Next
End Sub
| |
|
|
' ******************************************************
' 行の編集済みフラグクリア
' ******************************************************
Public Sub ClearRowDirty()
Dim count As Integer = Me.Rows.Count
Dim i As Integer
For i = count - 1 To 0 Step -1
CType(Me.Rows(i), lightbox.LboxGridRow).rowDirty = False
Next
End Sub
| |
|
|
FindNextRow、FindNextRowDirty |
|
|
' ******************************************************
' 行の取得
' ******************************************************
Public Function FindNextRow() As Boolean
FindNextRow = True
nCurrentRow += 1
If nCurrentRow + 1 > Me.Rows.Count Then
nCurrentRow = Me.Rows.Count - 1
FindNextRow = False
End If
End Function
' ******************************************************
' 行フラグが一致する行の取得
' ******************************************************
Public Function FindNextRow(ByVal flg As Integer) As Boolean
FindNextRow = False
Do While (Me.FindNextRow())
If Me.GetRowFlg() = flg Then
FindNextRow = True
Exit Do
End If
Loop
End Function
| |
|
サンプル
|
Me.LboxGrid1.SetCurrentRow()
Do While (Me.LboxGrid1.FindNextRow())
MessageBox.Show(CType(Me.LboxGrid1.GetColumnValue("CHECK"), Boolean))
Loop
| |
|
|
' ******************************************************
' 更新された行の取得
' ******************************************************
Public Function FindNextRowDirty() As Boolean
FindNextRowDirty = False
Do While (Me.FindNextRow())
If Me.GetRowDirty() Then
FindNextRowDirty = True
Exit Do
End If
Loop
End Function
| |
|
|
|
|
' ******************************************************
' カラム数取得
' ******************************************************
Public Function GetColumnCount() As Integer
GetColumnCount = Me.ColumnCount()
End Function
| |
|
|
|
|
' ******************************************************
' ヘッダのテキスト取得
' ******************************************************
Public Function GetColumnHeaderText(ByVal strName As String) As String
GetColumnHeaderText = Me.Columns(strName).HeaderText
End Function
Public Function GetColumnHeaderText(ByVal nIndex As Integer) As String
GetColumnHeaderText = Me.Columns(nIndex).HeaderText
End Function
| |
|
|
|
|
' ******************************************************
' カラムの番号取得
' ******************************************************
Public Function GetColumnIndex(ByVal strName As String) As Integer
GetColumnIndex = Me.Columns(strName).Index
End Function
| |
|
|
|
|
' ******************************************************
' カラムの名称取得
' ******************************************************
Public Function GetColumnName(ByVal nIndex As Integer) As String
GetColumnName = Me.Columns(nIndex).Name
End Function
| |
|
|
GetColumnText、GetColumnValue |
|
|
' ******************************************************
' カラムデータ取得
' ******************************************************
Public Function GetColumnText(ByVal strName As String) As String
GetColumnText = Me.Rows(nCurrentRow).Cells(strName).Value
End Function
Public Function GetColumnText(ByVal nCol As Integer) As String
GetColumnText = Me.Rows(nCurrentRow).Cells(nCol).Value
End Function
Public Function GetColumnText(ByVal nRow As Integer, _
ByVal strName As String) As String
GetColumnText = Me.Rows(nRow).Cells(strName).Value
End Function
Public Function GetColumnText(ByVal nRow As Integer, _
ByVal nCol As Integer) As String
GetColumnText = Me.Rows(nRow).Cells(nCol).Value
End Function
Public Function GetColumnValue(ByVal strName As String) As Object
GetColumnValue = Me.Rows(nCurrentRow).Cells(strName).Value
End Function
Public Function GetColumnValue(ByVal nCol As Integer) As Object
GetColumnValue = Me.Rows(nCurrentRow).Cells(nCol).Value
End Function
Public Function GetColumnValue(ByVal nRow As Integer, _
ByVal strName As String) As Object
GetColumnValue = Me.Rows(nRow).Cells(strName).Value
End Function
Public Function GetColumnValue(ByVal nRow As Integer, _
ByVal nCol As Integer) As Object
GetColumnValue = Me.Rows(nRow).Cells(nCol).Value
End Function
| |
|
|
GetCurrentRow、GetCurrentRowIndex |
|
|
' ******************************************************
' カレント行取得
' ******************************************************
Public Function GetCurrentRow() As Integer
GetCurrentRow = nCurrentRow
End Function
| |
|
|
Public Function GetCurrentRowIndex() As Integer
Return Me.CurrentCell.RowIndex
End Function
| |
|
|
|
|
' ******************************************************
' 行数取得
' ******************************************************
Public Function GetRowCount() As Integer
GetRowCount = Me.Rows.Count
End Function
| |
|
|
|
|
' ******************************************************
' 行フラグ取得
' ******************************************************
Public Function GetRowFlg() As Integer
GetRowFlg = CType(Me.Rows(nCurrentRow), lightbox.LboxGridRow).rowType
End Function
Public Function GetRowFlg(ByVal nIndex As Integer) As Integer
GetRowFlg = CType(Me.Rows(nIndex), lightbox.LboxGridRow).rowType
End Function
| |
|
|
|
|
' ******************************************************
' カラムを非表示にする
' ******************************************************
Public Sub HideColumn(ByVal nIndex As Integer)
Me.Columns(nIndex).Visible = False
End Sub
Public Sub HideColumn(ByVal strName As String)
Me.Columns(strName).Visible = False
End Sub
| |
|
|
|
|
' ******************************************************
' サイズ調整メソッド
' ******************************************************
Public Sub ParentFit(ByVal TargetForm As System.Windows.Forms.Form)
Me.Left = _SizeLeft
Me.Top = _SizeTop
Me.Width = TargetForm.ClientRectangle.Width - _SizeLeft - _SizeRight
Me.Height = TargetForm.ClientRectangle.Height - _SizeTop - _SizeBottom
End Sub
Public Sub ParentFit(ByVal TargetForm As System.Windows.Forms.TabControl)
Me.Left = _SizeLeft
Me.Top = _SizeTop
Me.Width = TargetForm.ClientRectangle.Width - _SizeLeft - _SizeRight - 8
Me.Height = TargetForm.ClientRectangle.Height - _SizeTop - _SizeBottom - 24
End Sub
Private _SizeLeft As Integer = 0
Private _SizeTop As Integer = 0
Private _SizeRight As Integer = 0
Private _SizeBottom As Integer = 0
' ******************************************************
' サイズ調整用位置プロパティ
' ******************************************************
Public Property SizeLeft() As Integer
Get
Return _SizeLeft
End Get
Set(ByVal value As Integer)
_SizeLeft = value
End Set
End Property
Public Property SizeRight() As Integer
Get
Return _SizeRight
End Get
Set(ByVal value As Integer)
_SizeRight = value
End Set
End Property
Public Property SizeTop() As Integer
Get
Return _SizeTop
End Get
Set(ByVal value As Integer)
_SizeTop = value
End Set
End Property
Public Property SizeBottom() As Integer
Get
Return _SizeBottom
End Get
Set(ByVal value As Integer)
_SizeBottom = value
End Set
End Property
| |
|
|
|
|
' ******************************************************
' 初期化
' ******************************************************
Public Sub Reset()
Me.Columns.Clear()
End Sub
| |
|
|
|
|
' ******************************************************
' カラム背景色設定
' ******************************************************
Public Sub SetColumnBackColor(ByVal nRow As Integer, _
ByVal strName As String, ByVal Color As System.Drawing.Color)
Me(strName, nRow).Style.BackColor = Color
End Sub
Public Sub SetColumnBackColor(ByVal nRow As Integer, _
ByVal nCol As Integer, ByVal Color As System.Drawing.Color)
Me(nCol, nRow).Style.BackColor = Color
End Sub
Public Sub SetColumnBackColor(ByVal strName As String, ByVal Color As System.Drawing.Color)
Me.Rows(nCurrentRow).Cells(strName).Style.BackColor = Color
End Sub
Public Sub SetColumnBackColor(ByVal nCol As Integer, ByVal Color As System.Drawing.Color)
Me.Rows(nCurrentRow).Cells(nCol).Style.BackColor = Color
End Sub
| |
|
|
|
|
' ******************************************************
' カラム色設定
' ******************************************************
Public Sub SetColumnColor(ByVal nRow As Integer, _
ByVal strName As String, ByVal Color As System.Drawing.Color)
Me(strName, nRow).Style.ForeColor = Color
End Sub
Public Sub SetColumnColor(ByVal nRow As Integer, _
ByVal nCol As Integer, ByVal Color As System.Drawing.Color)
Me(nCol, nRow).Style.ForeColor = Color
End Sub
Public Sub SetColumnColor(ByVal strName As String, ByVal Color As System.Drawing.Color)
Me.Rows(nCurrentRow).Cells(strName).Style.ForeColor = Color
End Sub
Public Sub SetColumnColor(ByVal nCol As Integer, ByVal Color As System.Drawing.Color)
Me.Rows(nCurrentRow).Cells(nCol).Style.ForeColor = Color
End Sub
| |
|
|
|
|
' ******************************************************
' ヘッダのテキスト変更
' ******************************************************
Public Sub SetColumnHeaderText(ByVal strName As String, ByVal strTitle As String)
Me.Columns(strName).HeaderText = strTitle
End Sub
Public Sub SetColumnHeaderText(ByVal nIndex As Integer, ByVal strTitle As String)
Me.Columns(nIndex).HeaderText = strTitle
End Sub
| |
|
|
|
|
' ******************************************************
' カラムの名称変更
' ******************************************************
Public Sub SetColumnName(ByVal strName As String, ByVal strNewName As String)
Me.Columns(strName).Name = strNewName
End Sub
Public Sub SetColumnName(ByVal nIndex As Integer, ByVal strName As String)
Me.Columns(nIndex).HeaderText = strName
End Sub
| |
|
|
SetColumnText、SetColumnValue |
|
|
' ******************************************************
' カラムデータ変更
' ******************************************************
Public Sub SetColumnText(ByVal nRow As Integer, _
ByVal strName As String, ByVal strText As String)
Me.Rows(nRow).Cells(strName).Value = strText
End Sub
Public Sub SetColumnText(ByVal nRow As Integer, _
ByVal nCol As Integer, ByVal strText As String)
Me.Rows(nRow).Cells(nCol).Value = strText
End Sub
Public Sub SetColumnText(ByVal strName As String, ByVal strText As String)
Me.Rows(nCurrentRow).Cells(strName).Value = strText
End Sub
Public Sub SetColumnText(ByVal nCol As Integer, ByVal strText As String)
Me.Rows(nCurrentRow).Cells(nCol).Value = strText
End Sub
Public Sub SetColumnValue(ByVal nRow As Integer, _
ByVal strName As String, ByVal value As Object)
Me.Rows(nRow).Cells(strName).Value = value
End Sub
Public Sub SetColumnValue(ByVal nRow As Integer, _
ByVal nCol As Integer, ByVal value As Object)
Me.Rows(nRow).Cells(nCol).Value = value
End Sub
Public Sub SetColumnValue(ByVal strName As String, ByVal value As Object)
Me.Rows(nCurrentRow).Cells(strName).Value = value
End Sub
Public Sub SetColumnValue(ByVal nCol As Integer, ByVal value As Object)
Me.Rows(nCurrentRow).Cells(nCol).Value = value
End Sub
| |
|
|
|
|
' ******************************************************
' カラムを表示・非表示
' ******************************************************
Public Sub SetColumnVisible(ByVal strName As String, ByVal bFlg As Boolean)
Me.Columns(strName).Visible = bFlg
End Sub
Public Sub SetColumnVisible(ByVal nCol As Integer, ByVal bFlg As Boolean)
Me.Columns(nCol).Visible = bFlg
End Sub
| |
|
|
|
|
' ******************************************************
' カラム幅変更
' ******************************************************
Public Sub SetColumnWidth(ByVal strName As String, ByVal nWidth As Integer)
Me.Columns(strName).Width = nWidth
End Sub
| |
|
|
|
|
' ******************************************************
' カレント行設定
' ******************************************************
Public Sub SetCurrentRow(ByVal nRow As Integer)
nCurrentRow = nRow
End Sub
Public Sub SetCurrentRow()
nCurrentRow = -1
End Sub
| |
|
|
Me.LboxGrid1.SetCurrentRow()
Do While (Me.LboxGrid1.FindNextRow())
MessageBox.Show(CType(Me.LboxGrid1.GetColumnValue("CHECK"), Boolean))
Loop
| |
|
|
|
|
' ******************************************************
' 固定列指定
' ******************************************************
Public Sub SetFixColumn(ByVal nCol As Integer)
Me.Columns(nCol).Frozen = True
End Sub
| |
|
|
|
|
' ******************************************************
' 指定カラムにフォーカスを移動にする
' ******************************************************
Public Sub SetFocusCell(ByVal nRow As Integer, _
ByVal strName As String)
Me.CurrentCell = Me(strName, nRow)
Me.BeginEdit(True)
End Sub
Public Sub SetFocusCell(ByVal nRow As Integer, _
ByVal nCol As Integer)
Me.CurrentCell = Me(nCol, nRow)
Me.BeginEdit(True)
End Sub
Public Sub SetFocusCell(ByVal strName As String)
Me.CurrentCell = Me(strName, Me.nCurrentRow)
Me.BeginEdit(True)
End Sub
Public Sub SetFocusCell(ByVal nCol As Integer)
Me.CurrentCell = Me(nCol, Me.nCurrentRow)
Me.BeginEdit(True)
End Sub
| |
|
|
|
|
' ******************************************************
' 行フラグ設定
' ******************************************************
Public Sub SetRowFlg(ByVal flg As Integer)
CType(Me.Rows(nCurrentRow), lightbox.LboxGridRow).rowType = flg
End Sub
Public Sub SetRowFlg(ByVal nIndex As Integer, ByVal flg As Integer)
CType(Me.Rows(nIndex), lightbox.LboxGridRow).rowType = flg
End Sub
| |
|
|
|
|
' ******************************************************
' 行選択状態の設定
' ******************************************************
Public Sub SetSelectRow(ByVal nRow As Integer, ByVal flg As Boolean)
Me.Rows(nRow).Selected = flg
End Sub
| |
|
|
|
|
' ******************************************************
' カラムを表示状態にする
' ******************************************************
Public Sub ShowColumn(ByVal nCol As Integer)
Me.Columns(nCol).Visible = True
End Sub
Public Sub ShowColumn(ByVal strName As String)
Me.Columns(strName).Visible = True
End Sub
| |
|
|
DisableColumnEdit、EnableColumnEdit |
|
|
' ******************************************************
' カラムを編集不可にする
' ******************************************************
Public Sub DisableColumnEdit(ByVal nIndex As Integer)
Me.Columns(nIndex).ReadOnly = True
End Sub
Public Sub DisableColumnEdit(ByVal strName As String)
Me.Columns(strName).ReadOnly = True
End Sub
| |
|
|
' ******************************************************
' カラムを編集可能にする
' ******************************************************
Public Sub EnableColumnEdit(ByVal nIndex As Integer)
Me.Columns(nIndex).ReadOnly = False
End Sub
Public Sub EnableColumnEdit(ByVal strName As String)
Me.Columns(strName).ReadOnly = False
End Sub
| |
|
|
|
|
Public Function GetColumnBoolean(ByVal strName As String) As Boolean
GetColumnBoolean = CType(Me.Rows(nCurrentRow).Cells(strName).Value, Boolean)
End Function
Public Function GetColumnBoolean(ByVal nCol As Integer) As Boolean
GetColumnBoolean = CType(Me.Rows(nCurrentRow).Cells(nCol).Value, Boolean)
End Function
Public Function GetColumnBoolean(ByVal nRow As Integer, _
ByVal strName As String) As Boolean
GetColumnBoolean = CType(Me.Rows(nRow).Cells(strName).Value, Boolean)
End Function
Public Function GetColumnBoolean(ByVal nRow As Integer, _
ByVal nCol As Integer) As Boolean
GetColumnBoolean = CType(Me.Rows(nRow).Cells(nCol).Value, Boolean)
End Function
| |
|
|
|
|
Public Function GetColumnTag(ByVal strName As String) As Object
GetColumnTag = Me.Rows(nCurrentRow).Cells(strName).Tag
End Function
Public Function GetColumnTag(ByVal nCol As Integer) As Object
GetColumnTag = Me.Rows(nCurrentRow).Cells(nCol).Tag
End Function
Public Function GetColumnTag(ByVal nRow As Integer, _
ByVal strName As String) As Object
GetColumnTag = Me.Rows(nRow).Cells(strName).Tag
End Function
Public Function GetColumnTag(ByVal nRow As Integer, _
ByVal nCol As Integer) As Object
GetColumnTag = Me.Rows(nRow).Cells(nCol).Tag
End Function
| |
|
|
|
|
' ******************************************************
' 編集済みフラグ取得
' ******************************************************
Public Function GetRowDirty() As Boolean
GetRowDirty = CType(Me.Rows(nCurrentRow), lightbox.LboxGridRow).rowDirty
End Function
Public Function GetRowDirty(ByVal nIndex As Integer) As Boolean
GetRowDirty = CType(Me.Rows(nIndex), lightbox.LboxGridRow).rowDirty
End Function
| |
|
|
|
|
' ******************************************************
' 行ヘッダ取得
' ******************************************************
Public Function GetRowHeadetText(ByVal nRow As Integer) As String
Return Me.Rows(nRow).HeaderCell.Value
End Function
Public Function GetRowHeadetText() As String
Return Me.Rows(nCurrentRow).HeaderCell.Value
End Function
| |
|
|
|
|
' ******************************************************
' 行フラグが一致する行があるかどうか
' ******************************************************
Public Function IsRowFlg(ByVal flg As Integer) As Boolean
IsRowFlg = False
Me.nCurrentRow = -1
Do While (Me.FindNextRow())
If Me.GetRowFlg() = flg Then
IsRowFlg = True
Exit Do
End If
Loop
End Function
| |
|
|
|
|
Public Sub SetColumnTag(ByVal nRow As Integer, _
ByVal strName As String, ByVal value As Object)
Me.Rows(nRow).Cells(strName).Tag = value
End Sub
Public Sub SetColumnTag(ByVal nRow As Integer, _
ByVal nCol As Integer, ByVal value As Object)
Me.Rows(nRow).Cells(nCol).Tag = value
End Sub
Public Sub SetColumnTag(ByVal strName As String, ByVal value As Object)
Me.Rows(nCurrentRow).Cells(strName).Tag = value
End Sub
Public Sub SetColumnTag(ByVal nCol As Integer, ByVal value As Object)
Me.Rows(nCurrentRow).Cells(nCol).Tag = value
End Sub
| |
|
|
|
|
' ******************************************************
' 編集済みフラグ設定
' ******************************************************
Public Sub SetRowDirty(ByVal flg As Boolean)
CType(Me.Rows(nCurrentRow), lightbox.LboxGridRow).rowDirty = flg
End Sub
Public Sub SetRowDirty(ByVal nIndex As Integer, ByVal flg As Boolean)
CType(Me.Rows(nIndex), lightbox.LboxGridRow).rowDirty = flg
End Sub
| |
|
|
|
|
' ******************************************************
' 行ヘッダ変更
' ******************************************************
Public Sub SetRowHeaderText(ByVal nRow As Integer, _
ByVal strText As String)
Me.Rows(nRow).HeaderCell.Value = strText
End Sub
Public Sub SetRowHeaderText(ByVal strText As String)
Me.Rows(nCurrentRow).HeaderCell.Value = strText
End Sub
| |
|
|
|