Empty Datagrid

I received an interesting comment from Jan Tielens about how to display an empty datagrid:

Hi guys, thanks for having me! ;-)

For the record, my work regarding datagrids is for Windows.Forms, so my opinion expressed here will also be for the Windows.Forms grid. Although maybe it's applicable for Web.Forms too, but I'm not in the position to judge about that.

First of all: it's an intresting question! To be honest I haven't thought about it yet. If I design a Windows.Forms form that shows a DataGrid, initially it will be empty (no data, message or column headers). I rarely create a from that shows data in a grid the first time I show it. I consider it "bad design" when people fill a grid with all the customers from the database, the first time a search form is displayed, because in 90% of the cases the user will want to search using his own criterea. But that's another discussion...

So how should the empty datagrid look like? It's technically possible to show the column headers by putting an empty collection in the grid. If we take a look at Microsoft how they do it for example when you use the "Search For Files or Folders", we'll see that they show the column headers and display the text "Enter your search criterea to begin.". Technically this is only possible if the first column of the grid can contain string values and is wide enough (or you should use a label or something that you display in front of the grid). Ofcourse the Microsoft search window uses a ListView control, that always shows it's columns, instead of the DataGrid control.

Personally I don't mind if the empty grid is a "grey box". If you want to be nice to your users, you can show a text by using the CaptionText property of the grid and/or you can display the column headers. From a user interface and user experience point-of-view it's a nice-to-have feature if the column headers are shown when the form is in it's initial state.

FYI: The home page for the ExtendedDataGrid is
http://dotnet.leadit.be/extendeddatagrid

My two cents on this Jan is about the case where you have the autogenerate columns enabled.

Basically you need in this case to have a sort of dataset, with some dummy values.
The other solution is probably to look at the last article on MSDN magazine from Dino Esposito.

He override the Render method to modify the Datagrid. So probably we can do the same to display something nice when no data are present.
The other idea is maybe to look at the undocumented method Dino used in his article CreateColumnSet.

 

1 Comment

Comments have been disabled for this content.