Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Maxim-CADman77
391 Views, 4 Replies

Crash (Endless loop) on any iteract to non-First row of DataGridView

(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  here)

 

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.

 

Here is a very simplified (Paint-created) version of the desired form:

Tabled-Options-Form.png

Pay attention there are some <empty> (not an option) cells.

 

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).

 

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 <empty cell>, at least all my attempts to do so were unsuccessful, see commented).
Then I search Internet a bit and found a mention that opposite conversation (from TextBoxCell to CheckBoxCell is possible).

Using this knowledge I get some progress towards the desired.


Now I can convert <empty cell> to checkbox with following iLogic code (see the DataBindingComplete sub):

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 = " & 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 = " & 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 = " & 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

 

BUT for some reason this behaves as expected ONLY for cells of the first row (row index = 0).
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).

 

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!

 

What I'm missing?

Please vote for Inventor-Idea Text Search within Option Names