I have a datagridview on my form and with this I am rendering its headers for the custom name style and the filter image.
What I want is :
To add the checkbox column with headercheckbox at the very first position not the zeroth index. I want it at -1.
To add some checkboxes at the particular columns.
I was able to add them at the wanted positions but it was not refreshing the interface and I was unable to get them check/unchecked.
Dim indx As Int16 = -1
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
tbIndex = 0 'mainTab.SelectedItem.Name.Substring(6)
If e.ColumnIndex >= 0 AndAlso e.RowIndex = -1 Then
If dic.ContainsKey(tbIndex) Then
indx = dic.Item(tbIndex)
Else
indx = -1
End If
e.PaintBackground(e.ClipBounds, False)
Dim pt As Point = e.CellBounds.Location
Dim offset As Integer = (e.CellBounds.Width - 25)
pt.X += offset
pt.Y = 5
If e.ColumnIndex = indx Then
e.Graphics.DrawImage(My.Resources.SortDSC, pt.X, pt.Y, 20, 20)
Else
e.Graphics.DrawImage(My.Resources.SortASC, pt.X, pt.Y, 20, 20)
End If
Dim drawFormat As System.Drawing.StringFormat = New System.Drawing.StringFormat()
drawFormat.FormatFlags = StringFormatFlags.NoFontFallback
e.Graphics.DrawString(dgv(tbIndex).Columns(e.ColumnIndex).HeaderText, New Font("Georgia", 10), Brushes.DodgerBlue, pt.X - offset, pt.Y + 15, drawFormat)
e.Handled = True
e.Handled = True
End If
End Sub
Private Sub DataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
If indx = e.ColumnIndex.ToString Then
indx = -1
Else
indx = e.ColumnIndex.ToString
End If
If Not dic.ContainsKey(tbIndex) Then
dic.Add(tbIndex, indx)
Else
dic.Remove(tbIndex)
dic.Add(tbIndex, indx)
End If
End Sub
I want to add them at runtime.