DataGrid Column Headers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a number of datagrids bound to collections. When the collections are
populated i get the column headings as per the ColumnStyles for the grid.
However if the collection is empty no column headings are visible.

Is there a way to force the headings to display other than having a dummy
item in the collection?

guy
 
Yes, implement a strongly typed indexer for the collection. Ofcourse
this won't work with built-in collections but only with custom collections.

For e.g. if your collection is of class Employee then you need to write
an indexer like this

public class EmployeeCollection : CollectionBase
{
public Employee this[int index]
{
get{ return List[index]; }
}
}

that's it..

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
many thanks:-)

guy

Sijin Joseph said:
Yes, implement a strongly typed indexer for the collection. Ofcourse
this won't work with built-in collections but only with custom collections.

For e.g. if your collection is of class Employee then you need to write
an indexer like this

public class EmployeeCollection : CollectionBase
{
public Employee this[int index]
{
get{ return List[index]; }
}
}

that's it..

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

I have a number of datagrids bound to collections. When the collections are
populated i get the column headings as per the ColumnStyles for the grid.
However if the collection is empty no column headings are visible.

Is there a way to force the headings to display other than having a dummy
item in the collection?

guy
 
Back
Top