Introduction
Gets or sets the text to display in the empty data row rendered when a DataGridView
control is bound to a data source that does not contain any records.
Background
The empty data row is displayed in a ASP.NET GridView control when the data source that is bound to the control does not contain any records. Use the <span>EmptyDataText</span>
property to specify the text to display in the empty data row using EmptyDataRowStyle in ASP.NET. But this is not in Windows Form Application, so I have created a Component for this functionality.
Using the Code
The following screen displays properties of EmptyDataText Grid
component.
Binding grid with 0 records:
After binding grid, it looks like:
The following code is self explanatory. The following code has been written in Component\DataGrid.cs. In DataGrid.cs, I have Overrides Pint method of DataGridView
.
The following code has been written in Form1.cs:
Points of Interest
Now I will try to support automatic label display instead of checking the following lines of code:
dgEmptyData.DataSource = dt;
if (dt != null && dt.Rows.Count > 0)
dgEmptyData.EmptyDataText = "";
else
dgEmptyData.EmptyDataText = txtEmptyText.Text;
History
If you find some issues or bugs with it, just leave a comment or drop me an email. If you make any notes on this, let me know that too so I don't have to redo any of your hard work.
Please provide a "Vote" if this would be helpful.