EmptyDataText
является собственностью элемента управления веб-форм GridView
.В Windows Forms, чтобы отобразить текст, когда DataGridView
не имеет строки, вам нужно визуализировать текст самостоятельно.Для этого вы можете обработать Paint
событие DataGridView
и визуализировать текст, используя TextRenderer.DrawText
.
C #
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
if (dataGridView1.Rows.Count == 0)
TextRenderer.DrawText(e.Graphics, "No records found.",
dataGridView1.Font, dataGridView1.ClientRectangle,
dataGridView1.ForeColor, dataGridView1.BackgroundColor,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
}
VB.NET
Private Sub DataGridView1_Paint(sender As Object, e As PaintEventArgs) _
Handles DataGridView1.Paint
If DataGridView1.Rows.Count = 0 Then
TextRenderer.DrawText(e.Graphics, "No records found.",
DataGridView1.Font, DataGridView1.ClientRectangle,
DataGridView1.ForeColor, DataGridView1.BackgroundColor,
TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter)
End If
End Sub