<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Disabling checkboxes in pivoted DataTable provokes poor-painted DataGridView in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11972164#M23591</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;My current code is:&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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 &amp;gt;= 0 And e.ColumnIndex &amp;gt;= 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If DataTable is created as Vertical (line 26) then I get 100% OK result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vert-Table-OK.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1216070i1789FE8D4C11ADE7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vert-Table-OK.png" alt="Vert-Table-OK.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hor-Table-Cell-Pint-FAILURE.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1216072i99C0AE16B6FD95BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hor-Table-Cell-Pint-FAILURE.png" alt="Hor-Table-Cell-Pint-FAILURE.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS:&lt;BR /&gt;Dear&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/537534"&gt;@MjDeck&lt;/a&gt;&amp;nbsp;I'm very sorry for disturbing you but,&amp;nbsp;I understand that this thread is not Inventor-related but&amp;nbsp;kindly hope you can look into and comment on this.&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2023 08:13:28 GMT</pubDate>
    <dc:creator>Maxim-CADman77</dc:creator>
    <dc:date>2023-05-18T08:13:28Z</dc:date>
    <item>
      <title>Crash (Endless loop) on any iteract to non-First row of DataGridView</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11965329#M23588</link>
      <description>&lt;P&gt;(this thread seems related to general programming but as soon as I suffer the issue in context of Inventor-relatad project I hope it is not too-much off-topic&amp;nbsp; here)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In one of my Inventor-related projects I'd like to provide user with Windows Form containing controls of some options (CheckBoxes) organized with DataGridView.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a very simplified (Paint-created) version of the desired form:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tabled-Options-Form.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1214694iB973580CD8690B8B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tabled-Options-Form.png" alt="Tabled-Options-Form.png" /&gt;&lt;/span&gt; &lt;/P&gt;&lt;P&gt;Pay attention there are some &amp;lt;empty&amp;gt; (not an option) cells.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hard thing of this task - irregularity of the CheckBoxCell pattern (should be generated dynamically according to some business logic that is not an object of this thread).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initially I thought I need to use Boolean type for Columns where CheckBoxes are to be placed but that seems to be the wrong way (AFAIK CheckBoxCell can't be converted to an &amp;lt;empty cell&amp;gt;, at least all my attempts to do so were unsuccessful, see commented).&lt;BR /&gt;Then I search Internet a bit and found a mention that opposite conversation (from TextBoxCell to CheckBoxCell is possible).&lt;/P&gt;&lt;P&gt;Using this knowledge I get some progress towards the desired.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now I can convert &amp;lt;empty cell&amp;gt; to checkbox with following iLogic code (see the DataBindingComplete sub):&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Option Explicit On

AddReference "System.Data"
AddReference "System.Xml"
Imports System.Data
Imports System.Windows.Forms


Class AAA

Friend WithEvents oDGV As New DataGridView

Dim sHeader1 As String = "Name"
Dim sHeader2 As String = "Option1"
Dim sHeader3 As String = "Option2"


Sub Main

Dim oDT As DataTable = New DataTable

oDT.Columns.Add(sHeader1, GetType(String))
oDT.Columns.Add(sHeader2, GetType(String)) ' GetType(Boolean))
oDT.Columns.Add(sHeader3, GetType(String)) ' GetType(Boolean))

Dim names = New List(Of String)
names.Add("A1")
names.Add("A2")

' Dim opt1vals = New List(Of String)
' opt1vals.Add(False)
' opt1vals.Add(True)

' Dim opt2vals = New List(Of String)
' opt2vals.Add(True)
' opt2vals.Add(False)

Dim i As Integer = 0
For Each name in Names
	oDT.Rows.Add(oDT.Columns.Count)
	oDT.Rows(i)(sHeader1) = name
	' oDT.Rows(i)(sHeader2) = opt1vals(i)
	' oDT.Rows(i)(sHeader3) = opt2vals(i)
	i +=1
Next


Dim oDV As DataView = oDT.DefaultView

With oDGV
	.AllowUserToAddRows = False
	.AutoSize = True
	.DataSource = oDV
End With


Dim oForm As New Form
With oForm
	.AutoSize = True
	.Controls.Add(oDGV)
End With

' logger.info("oDGV.Rows.Count #1 = " &amp;amp; oDGV.Rows.Count)

oForm.ShowDialog()

End Sub


Sub oDGV_DataBindingComplete(ByVal sender As Object, ByVal E As DataGridViewBindingCompleteEventArgs) Handles oDGV.DataBindingComplete

	logger.info("oDGV.Rows.Count #2 = " &amp;amp; oDGV.Rows.Count)

	oDGV.Rows(0).Cells(sHeader3).Value = True
	oDGV.Rows(0).Cells(sHeader3) = New DataGridViewCheckBoxCell()

	' oDGV.Rows(1).Cells(sHeader2).Value = True ' !!! ENDLESS-LOOP
	' oDGV.Rows(1).Cells(sHeader2) = New DataGridViewCheckBoxCell()
	
End Sub

' Sub oDGV_DataBindingComplete(ByVal sender As Object, ByVal E As DataGridViewBindingCompleteEventArgs) Handles oDGV.DataBindingComplete
	' logger.info("oDGV.Rows.Count-2 = " &amp;amp; oDGV.Rows.Count)

	' oDGV.Rows(0).Cells(sHeader2).Value = False
	' oDGV.Rows(0).Cells(sHeader2) = New DataGridViewTextBoxCell()
	' oDGV.Rows(0).Cells(sHeader2).Value = ""
' End Sub

End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT for some reason this behaves as expected ONLY for cells of the first row (row index = 0).&lt;BR /&gt;As soon as I try to do this for a cell in the second row (row index = 1) the code crashes (after some time of endless cycling ... which I detect by means of iLogic Log panel).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the problem seems not the conversation itself ... the code goes to endless cycle even if I comment-out those two lines related to the second row but try to interact with any cell of second row!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I'm missing?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 18:38:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11965329#M23588</guid>
      <dc:creator>Maxim-CADman77</dc:creator>
      <dc:date>2023-05-15T18:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Crash (Endless loop) on any iteract to non-First row of DataGridView</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11966383#M23589</link>
      <description>&lt;P&gt;I've managed to get a bit closer to what I want with approach of disabling existing checkbox with the code based on CellPainting Event handle:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Option Explicit On

AddReference "System.Data"
AddReference "System.Drawing"
AddReference "System.Xml"
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms


Class AAA

Friend WithEvents oDGV As New DataGridView

Dim sHeader1 As String = "Name"
Dim sHeader2 As String = "Option1"
Dim sHeader3 As String = "Option2"


Sub Main

Dim oDT As DataTable = New DataTable

oDT.Columns.Add(sHeader1, GetType(String))
oDT.Columns.Add(sHeader2, GetType(Boolean))
oDT.Columns.Add(sHeader3, GetType(Boolean))

Dim names = New List(Of String)
names.Add("A1")
names.Add("A2")

Dim opt1vals = New List(Of String)
opt1vals.Add(False)
opt1vals.Add(True)

Dim opt2vals = New List(Of String)
opt2vals.Add(True)
opt2vals.Add(False)

Dim i As Integer = 0
For Each name in Names
	oDT.Rows.Add(oDT.Columns.Count)
	oDT.Rows(i)(sHeader1) = name
	oDT.Rows(i)(sHeader2) = opt1vals(i)
	oDT.Rows(i)(sHeader3) = opt2vals(i)
	i +=1
Next


Dim oDV As DataView = oDT.DefaultView

With oDGV
	.AllowUserToAddRows = False
	.AutoSize = True
	.DataSource = oDV
End With


Dim oForm As New Form
With oForm
	.AutoSize = True
	.Controls.Add(oDGV)
End With

oForm.ShowDialog()

End Sub


Sub oDGV_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles oDGV.CellPainting
	logger.info(1)

	' If e.RowIndex = 0 And e.ColumnIndex = 1 ' sHeader2
		' Dim cell1 As DataGridViewCell = oDGV.Rows(0).Cells(sHeader2)
		' Dim chkCell1 As DataGridViewCheckBoxCell = TryCast(cell1, DataGridViewCheckBoxCell)
		' chkCell1.Value = False
		' chkCell1.FlatStyle = FlatStyle.Flat
		' chkCell1.Style.ForeColor = Color.DarkGray
		' cell1.ReadOnly = True
	' End If

	If e.RowIndex = 1 And e.ColumnIndex = 2 
		Dim cell2 As DataGridViewCell = oDGV.Rows(1).Cells(sHeader3)
		Dim chkCell2 As DataGridViewCheckBoxCell = TryCast(cell2, DataGridViewCheckBoxCell)
		chkCell2.Value = False
		chkCell2.FlatStyle = FlatStyle.Flat
		chkCell2.Style.ForeColor = Color.DarkGray
		cell2.ReadOnly = True
	End If

End Sub

End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I can &lt;STRIKE&gt;clear&lt;/STRIKE&gt; &lt;STRONG&gt;disable&lt;/STRONG&gt; checkboxes not only in the first row.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CheckBox-Chart-with-Disabled-Instances.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1214897i4A35EF694B92B34C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CheckBox-Chart-with-Disabled-Instances.png" alt="CheckBox-Chart-with-Disabled-Instances.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;But I still worry about the fact that the sub is called 24 times for single cell and get to endless cycle (at least without crashing) if un-comment the code lines related to the checkbox in a first row ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... I believe it will crash on real check box chart with dozens checkboxes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 05:45:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11966383#M23589</guid>
      <dc:creator>Maxim-CADman77</dc:creator>
      <dc:date>2023-05-16T05:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Crash (Endless loop) on any iteract to non-First row of DataGridView</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11966811#M23590</link>
      <description>&lt;P&gt;Ok endless loop seems to be triggered with cell value line(s):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;chkCell1.Value = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Event Handler Sub shouldn't contain lines changing cells' values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still don't understand why the sub is triggered so many times yet now I got more-or-less what I need without endless cycle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS:&lt;/P&gt;&lt;P&gt;I'll keep the thread open for some time in case somebody want to share a better solution.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 09:31:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11966811#M23590</guid>
      <dc:creator>Maxim-CADman77</dc:creator>
      <dc:date>2023-05-16T09:31:36Z</dc:date>
    </item>
    <item>
      <title>Disabling checkboxes in pivoted DataTable provokes poor-painted DataGridView</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11972164#M23591</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;My current code is:&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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 &amp;gt;= 0 And e.ColumnIndex &amp;gt;= 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If DataTable is created as Vertical (line 26) then I get 100% OK result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vert-Table-OK.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1216070i1789FE8D4C11ADE7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vert-Table-OK.png" alt="Vert-Table-OK.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hor-Table-Cell-Pint-FAILURE.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1216072i99C0AE16B6FD95BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hor-Table-Cell-Pint-FAILURE.png" alt="Hor-Table-Cell-Pint-FAILURE.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS:&lt;BR /&gt;Dear&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/537534"&gt;@MjDeck&lt;/a&gt;&amp;nbsp;I'm very sorry for disturbing you but,&amp;nbsp;I understand that this thread is not Inventor-related but&amp;nbsp;kindly hope you can look into and comment on this.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 08:13:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/11972164#M23591</guid>
      <dc:creator>Maxim-CADman77</dc:creator>
      <dc:date>2023-05-18T08:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Crash (Endless loop) on any iteract to non-First row of DataGridView</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/12005605#M23592</link>
      <description>&lt;P&gt;Hi Maxim - the CellPainting event is not a good place to do this. That's more suited for customizing the appearance of the cell.&amp;nbsp;&lt;BR /&gt;Here's a new version of your rule. This sets the read-only state with the same logic that you were using in oDgv_CellPainting. But it does it in the Form.Shown event. The system will call that only once, and it will call it after the DataGridView has been populated. So that's a good time to set some cells to read-only.&lt;BR /&gt;I also made a small change to the&amp;nbsp;Rows.Add() lines. You were calling them with the columns count as an argument. I think that value is ignored, so I took it out just to make the code more clear. Let me know if I missed something here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:45:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/crash-endless-loop-on-any-iteract-to-non-first-row-of/m-p/12005605#M23592</guid>
      <dc:creator>MjDeck</dc:creator>
      <dc:date>2023-06-01T22:45:53Z</dc:date>
    </item>
  </channel>
</rss>

