Question Where is the feature of my DataGridView

Socarsky

Well-known member
Joined
Dec 27, 2012
Messages
173
Location
Jakarta/Indonesia
Programming Experience
Beginner
Which code line or any property of DataGridView caused not to see <No Data to Display> string in the middle of DataGridView with its property of paint?
Here the code:
Private Sub SetUpDataGridView()
        Me.Controls.Add(DataGridView1)

        With DataGridView1.ColumnHeadersDefaultCellStyle
            .BackColor = Color.Navy
            .ForeColor = Color.White
            .Font = New Font(DataGridView1.Font, FontStyle.Bold)
        End With

        With DataGridView1
            .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
            .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
            .CellBorderStyle = DataGridViewCellBorderStyle.Single
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
            .GridColor = SystemColors.ActiveBorder
            .Font = New Font("Franklin Gothic Book", DataGridView1.DefaultCellStyle.Font.Size * 1 * 0.95, FontStyle.Regular, GraphicsUnit.Point)
            .RowHeadersVisible = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
            .BackgroundColor = Color.Honeydew
        End With
    End Sub


  Private Sub DataGridView1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
        If DataGridView1.RowCount = 0 Then
            Using brsh As New SolidBrush(Color.DarkBlue)
                Using fmt As New StringFormat
                    Dim drawFont As New Font("Arial", 16)
                    fmt.Alignment = StringAlignment.Center
                    e.Graphics.DrawString("<No data to display>", drawFont, brsh,
                                          DataGridView1.Left + (DataGridView1.Width / 2), DataGridView1.Top + (DataGridView1.Height / 2), fmt)
                End Using
            End Using
        End If
    End Sub


If I use a simple DataGridView then I can see the feature like below
Clipboard01dd.jpg
 
I'm not really sure what you're asking. There is no magic to make that text appear. You've got to do it manually. You already are doing it manually though, so what's the question?
 
I'm not really sure what you're asking. There is no magic to make that text appear. You've got to do it manually. You already are doing it manually though, so what's the question?
MY question is first code block that in my project as setting up a DataGridView and second one DataGridView paint method and I also use it like that but I think first block of code above effects the DataGridView appearing with <no data to display> I am just asking that why first block effects its appearing that I want to use.
 
Back
Top