Option Explicit On AddReference "System.Data" AddReference "System.Drawing" AddReference "System.Xml" Imports System.Data Imports System.Drawing Imports System.Windows.Forms Class UserSetsForm Friend WithEvents oForm As New Form Friend WithEvents oDGV As New DataGridView Dim sHeader1 As String = " " Dim sHeaderIPT As String = "*.ipt" Dim sHeaderIAM As String = "*.iam" Dim sHeaderIDW As String = "*.idw" Sub Main Dim optNames = New List(Of String) optNames.AddRange({"00-AAA", "2D-AAA", "3D-AAA", "00-ABC", "2D-ABC", "3D-ABC"}) Dim oDT As DataTable = dataTableVERT(optNames) 'Dim oDT As DataTable = dataTableHOR(optNames) Dim oDV As DataView = oDT.DefaultView With oDGV .AllowUserToAddRows = False .AutoSize = True .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells .BackgroundColor = Drawing.Color.White .DataSource = oDV End With With oForm .AutoSize = True .Controls.Add(oDGV) End With oForm.ShowDialog() End Sub Function dataTableVERT(optNames As List(Of String)) As dataTable Dim oDT_V As DataTable = New DataTable oDT_V.Columns.Add(sHeader1, GetType(String)) oDT_V.Columns.Add(sHeaderIPT, GetType(Boolean)) oDT_V.Columns.Add(sHeaderIAM, GetType(Boolean)) oDT_V.Columns.Add(sHeaderIDW, GetType(Boolean)) Dim i As Integer = 0 For Each cn in optNames oDT_V.Rows.Add() oDT_V.Rows(i)(sHeader1) = cn i +=1 Next Return oDT_V End Function Function dataTableHOR(optNames As List(Of String)) As dataTable Dim oDT_H As DataTable = New DataTable oDT_H.Columns.Add(sHeader1, GetType(String)) For Each cn in optNames oDT_H.Columns.Add(cn, GetType(Boolean)) Next oDT_H.Rows.Add() oDT_H.Rows(0)(sHeader1) = sHeaderIPT oDT_H.Rows.Add() oDT_H.Rows(1)(sHeader1) = sHeaderIAM oDT_H.Rows.Add() oDT_H.Rows(2)(sHeader1) = sHeaderIDW Return oDT_H End Function Sub SetReadOnlyCells() If oDGV.Columns.Count = 4 Then ' Vertical Logger.Debug("-- Vertical --") For Each rowX As DataGridViewRow In oDGV.Rows For Each cellX As DataGridViewCell In rowX.Cells if cellX.ColumnIndex = 0 Then Continue For Dim colX = cellX.OwningColumn Dim colIs2d As Boolean = colX.HeaderText = sHeaderIDW Dim optText = rowX.Cells(0).Value.ToString() Logger.Debug("colIs2d = {0}, optText = {1}", colIs2d, optText) If (colIs2d And optText.StartsWith("3D")) Or (Not colIs2d And optText.StartsWith("2D")) Then ChkBoxDisable(cellX) End If Next Next Else ' Horizontal Logger.Debug("-- Horizontal --") For Each rowX As DataGridViewRow In oDGV.Rows For Each cellX As DataGridViewCell In rowX.Cells Dim colX = cellX.OwningColumn Dim rowHeader = rowX.Cells(0).Value.ToString() Dim rowIs2d As Boolean = rowHeader = sHeaderIDW Dim optText = colX.HeaderText Logger.Debug("rowIs2d = {0}, optText = {1}", rowIs2d, optText) If (rowIs2d And optText.StartsWith("3D")) Or (Not rowIs2d And optText.StartsWith("2D")) Then ChkBoxDisable(cellX) End If Next Next End If End Sub Sub ChkBoxDisable(cell As DataGridViewCell) Dim chkCell As DataGridViewCheckBoxCell = TryCast(cell, DataGridViewCheckBoxCell) chkCell.FlatStyle = FlatStyle.Flat chkCell.Style.ForeColor = Color.DarkGray cell.ReadOnly = True End Sub Sub oForm_OnShown(ByVal sender As Object, ByVal e As EventArgs) Handles oForm.Shown SetReadOnlyCells() End Sub End Class