finding the header item in a datagrid

  • Thread starter Thread starter GaryB
  • Start date Start date
G

GaryB

The datagrid.items collection only appears to have data rows in it. for
Instance...
dim myItem ad dataGridItem
myItem = myGrid.Items(0)

returns the first data row of data.

How can I access the Headertext and footer text? The docs say ...

" A DataGridItem represents an item (row) in a DataGrid control, such as a
heading section, a footer section, or a data row." So, it must be possible
to access it.

Anyone know how?
Thanks,
Gary
 
You may be able to get at them in more places, but I've always used the
ItemCreated event that gets triggered as the grid gets built. You can
check the type of item (header, footer...) that is being created and
modify it before it gets placed.

Have A Better One!

John M Deal, MCP
Necessity Software
 
Hi GaryB:

Yes, tis true. The Items collection only contains data bound items,
but the Controls collection will contain everything.

You can assume Controls[0] will have the DataGridItem for the header,
and Controls[Controls.Length - 1] will have the DataGridItem for the
footer.
 
I had the same problem. Those docs are bogus. The items collection only
has the data rows. If you want to access header fields you need to use the
columns collection. For instance to see how a column is justified you would
say...
if myGrid.columns(i).HeaderStyle.HorizontalAlign = HorizontalAlign.right
then....

to see how a column is aligned.
T
 
Hi Gary,

If you walk the Controls collection far enough you can get it as a table
cell.

Private Sub DataGrid1_PreRender _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DataGrid1.PreRender
Dim dgCell As TableCell
dgCell = CType(DataGrid1.Controls(0). _
Controls(0). _
Controls(0), _
TableCell)
dgCell.Text = "Hey look here!"
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
 
I finally found that the HeaderText is in the columns collection as Tina
indicated. I had used that before but the bogus docs had me looking
elsewhere.
Gary

Ken Cox said:
Hi Gary,

If you walk the Controls collection far enough you can get it as a table
cell.

Private Sub DataGrid1_PreRender _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DataGrid1.PreRender
Dim dgCell As TableCell
dgCell = CType(DataGrid1.Controls(0). _
Controls(0). _
Controls(0), _
TableCell)
dgCell.Text = "Hey look here!"
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

GaryB said:
The datagrid.items collection only appears to have data rows in it. for
Instance...
dim myItem ad dataGridItem
myItem = myGrid.Items(0)

returns the first data row of data.

How can I access the Headertext and footer text? The docs say ...

" A DataGridItem represents an item (row) in a DataGrid control, such as
a heading section, a footer section, or a data row." So, it must be
possible to access it.

Anyone know how?
Thanks,
Gary
 
Back
Top