- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The form I'm working on will have much more options than names thus I decided to optimize it a bit - swap rows with columns (AFAIK such table transformation is called "Pivot") but got to some re-paint issue that I don't understand how to overcome.
My current code is:
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 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
Dim oForm As New Form
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.Columns.Count)
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.Columns.Count)
oDT_H.Rows(0)(sHeader1) = sHeaderIPT
oDT_H.Rows.Add(oDT_H.Columns.Count)
oDT_H.Rows(1)(sHeader1) = sHeaderIAM
oDT_H.Rows.Add(oDT_H.Columns.Count)
oDT_H.Rows(2)(sHeader1) = sHeaderIDW
Return oDT_H
End Function
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 oDGV_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles oDGV.CellPainting
''' Disable choosing non-applicable check-boxes
If e.RowIndex >= 0 And e.ColumnIndex >= 1
Dim row As DataGridViewRow = oDGV.Rows(e.RowIndex)
Dim column As DataGridViewColumn = oDGV.Columns(e.ColumnIndex)
Select Case True
''' CASES-for-VERTICAL-table
Case row.Cells(sHeader1).Value.StartsWith("2D-") And (column.HeaderText = sHeaderIPT OR column.HeaderText = sHeaderIAM)
ChkBoxDisable(oDGV.Rows(e.RowIndex).Cells(sHeaderIAM))
ChkBoxDisable(oDGV.Rows(e.RowIndex).Cells(sHeaderIPT))
Case row.Cells(sHeader1).Value.StartsWith("3D-") And (column.HeaderText = sHeaderIDW)
ChkBoxDisable(oDGV.Rows(e.RowIndex).Cells(sHeaderIDW))
''' CASES-for-HORIOZONTAL-table (??? poor-painting ???)
Case column.HeaderText.StartsWith("2D-") AndAlso (row.Cells(sHeader1).Value = sHeaderIPT OR row.Cells(sHeader1).Value = sHeaderIAM)
ChkBoxDisable(oDGV.Rows(sHeaderIPT).Cells(e.ColumnIndex))
ChkBoxDisable(oDGV.Rows(sHeaderIAM).Cells(e.ColumnIndex))
Case column.HeaderText.StartsWith("3D-") AndAlso row.Cells(sHeader1).Value = sHeaderIDW
ChkBoxDisable(oDGV.Rows(sHeaderIDW).Cells(e.ColumnIndex))
End Select
End If
End Sub
End Class
If DataTable is created as Vertical (line 26) then I get 100% OK result:
But if DataTable is created Horizontal/"Pivoted" (line 27) then most cells got stuck until hovered with mouse pointer (but even re-drawed with pointer the disabled checkboxes are not shown):
PS:
Dear @MjDeck I'm very sorry for disturbing you but, I understand that this thread is not Inventor-related but kindly hope you can look into and comment on this.
Please vote for Inventor-Idea Text Search within Option Names