Click here to Skip to main content
Licence CPOL
First Posted 5 May 2011
Views 8,653
Downloads 1,344
Bookmarked 13 times

DataGridView component with EmptyDataText Property - Windows Form Application

By | 5 May 2011 | Article
Gets or sets the text to display in the empty data row rendered when a GridView control is bound to a data source that does not contain any records

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 EmptyDataText 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.

EDTScreen.png

Binding grid with 0 records:

EDT_without_data.png

After binding grid, it looks like:

EDT_with_data.png

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.

Grid_Component.png

The following code has been written in Form1.cs:

Grid_Example.png

Points of Interest

Now I will try to support automatic label display instead of checking the following lines of code:

//You should use only following 5 lines of code.
            dgEmptyData.DataSource = dt;
            if (dt != null && dt.Rows.Count > 0)
                //Remove text when records exists
                dgEmptyData.EmptyDataText = "";
            else
                //Assign text when no record found
                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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sunasara Imdadhusen

Software Developer (Senior)
Verve Systems Ahmedabad-Gujarat
India India

Member

Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen
+91 99095 44184
 
AWARDS:
  1. 1st Best Asp.Net article of SEP 2010
  2. 2nd Best Asp.Net article of MAY 2011
 
Read More Articles...

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 6 May 2011
Article Copyright 2011 by Sunasara Imdadhusen
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid