finding the header item in a datagrid

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
 
J

John M Deal

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
 
S

Scott Allen

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

Tina

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
 
K

Ken Cox [Microsoft MVP]

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]
 
G

GaryB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top