0

upon initialization of my UI i get the following very strange behavior regarding to the drawing of the datagridview: enter image description here

Basically, expect the first row header and the column headers (which i did not include in the pic) it looks like the DGV prints what is on the Screen "behind" his application.
What the hell is this and does anyone know a way to fix it?

Code of Container:

Public Class DGVControl
    Dim dt As DataTable
    Public Sub init()
        dt = New DataTable
        Dim arr(ldfAttributes.Count - 1) As String

        Dim cms As New ContextMenuStrip

        Dim i As Integer = 0
        For Each att As String In Attributes.Keys
            Dim cmsitem As New ToolStripMenuItem
            dt.Columns.Add(att, GetType(String))
            cmsitem.Name = att
            cmsitem.Text = att
            cmsitem.Owner = cms
            cmsitem.CheckOnClick = True
            cmsitem.Checked = my.Settings.shownColumns.Contains(att)
            AddHandler cmsitem.CheckedChanged, AddressOf showOrHideColumn
            cms.Items.Add(cmsitem)
            arr(i) = "No Data"
            i += 1
        Next

        For i = 1 To my.settings.anzEntries
            dt.Rows.Add(arr)
        Next
        MainDGV.DataSource = dt
        MainDGV.ContextMenuStrip = cms
        For Each attName as String In Attributes.key
            showOrHideColumn(cms.Items(attName), New EventArgs())
        Next

        MainDGV.RowHeadersWidth = 90
        MainDGV.RowTemplate.Height = 40

        MainDGV.RowHeadersDefaultCellStyle.BackColor = Color.White
        MainDGV.RowHeadersDefaultCellStyle.Font = New Font(MainDGV.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
        MainDGV.ColumnHeadersDefaultCellStyle.BackColor = Color.White
        MainDGV.ColumnHeadersDefaultCellStyle.Font = New Font(MainDGV.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)

        MainDGV.BackgroundColor = Color.White
    End Sub

    Private Sub showOrHideColumn(sender As Object, e As EventArgs)
        Dim cmsitem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        MainDGV.Columns(cmsitem.Name).Visible = cmsitem.Checked
    End Sub
    'taken from: http://stackoverflow.com/questions/710064/adding-text-to-datagridview-row-header
    Private Sub nameRowHeaders(sender As Object, e As EventArgs) Handles MainDGV.DataBindingComplete
        Dim dgv As DataGridView = CType(sender, DataGridView)
        For i As Integer = 0 To dgv.RowCount - 1
            dgv.Rows(i).HeaderCell.Value = ("Entry " &(i+1).toString())
        Next
    End Sub



End Class

EDIT: As soon as you once select a row, all cells will be displayed in the right way until you restart the application

lsteinme
  • 750
  • 1
  • 6
  • 20
  • Have you changed your form's transparency key to something other than the default? Or indeed the dgv backcolour to the same as the form transparency key – David Wilson Feb 25 '16 at 09:32
  • no, in fact if I add the same usercontrol a second time below the first one, the first one will be displayed the right way, while the second one again gets this bug – lsteinme Feb 25 '16 at 09:33
  • Try changing the form transparency key to something else. – David Wilson Feb 25 '16 at 09:36
  • that does remove the image of the screen behind, but the initialization is still wrong, because now the fields that where "transparent" before are just white but do not get painted correctly (with content etc.) – lsteinme Feb 25 '16 at 09:47
  • I guess the next thing to to is to check the dgv's backcolor and gridcolor – David Wilson Feb 25 '16 at 09:48
  • are you able to reproduce this problem on your dev machine? – Takarii Feb 25 '16 at 09:51
  • I might be able to after some work creating the objects in the class. I notice that there is code in the class that changes theMainDGV.RowHeadersDefaultCellStyle.BackColor and MainDGV.ColumnHeadersDefaultCellStyle.BackColor and the maindgv.backcolor. Im curious though why you have a class that refers to objects outside the class. To me that seems like less than ideal programming practice. – David Wilson Feb 25 '16 at 09:57
  • Unless of course DGVControl is the name of your main form :) – David Wilson Feb 25 '16 at 10:00
  • no it is just a Usercontrol, MainDGV is a Datagridview in the usercontrol (and sole component as well). Attributes is a dictionary in a module and contains attributenames as well as calculation formulars that are read at programstart from a file. I admit not very nice, but needed because there is a big rat's tale associated with this attributes which luckly does not effect the dgv xD – lsteinme Feb 25 '16 at 10:12
  • Fair enough. I presume then that you inherited the project :) Does changing the properties I mentioned help btw? – David Wilson Feb 25 '16 at 10:16
  • Yes to the first, no to the second, sorry – lsteinme Feb 25 '16 at 10:23
  • Damn. Maybe there is code elsewhere in the project that alters some/all of the above settings – David Wilson Feb 25 '16 at 10:37
  • Are there any dgv paint event handlers (i.e.: CellPainting, RowPrePaint, RowPostPaint)? I've seen similar behavior when I mucked those up. – TnTinMn Feb 25 '16 at 11:15
  • No costume ones as of yet, I was planning to build one, but at present there is non expect the default ones – lsteinme Feb 25 '16 at 11:35

0 Answers0