05-15-2023
10:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-15-2023
10:38 PM
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:
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
Now I can clear disable checkboxes not only in the first row.
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 ...
... I believe it will crash on real check box chart with dozens checkboxes.
Any ideas?
Please vote for Inventor-Idea Text Search within Option Names