Subheaders in Datagrid?

G

Guest

Hi all,

Is it possible to create subheaders in datagrids? Or rather to add a parent
header row to an existing datagrid? Currently my DG looks like this:

NAME | A - PART1 | A - PART2 | A - PART3 | B - PART1 | B - PART2

whereas id like it to look like:

NAME | A | B |
|PART1 | PART2 | PART3| PART1 | PART2|

or

| A | B
|
NAME |PART1 | PART2 | PART3| PART1 | PART2|

Im trying to intercept the databind event and checking for item type =
header, but am getting a bit stuck after that. IS that the correct approach,
or is there another way?

Thanks!

Spammy
 
J

John Oakes

Something like this will work:

Private Sub GrdName_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GrdName.PreRender
'Add header to datagrid
Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)
Dim mycell As New TableCell
mycell.Text = ""
mycell.BackColor = Color.White
dgitem.Cells.Add(mycell)
GrdName.Controls(0).Controls.AddAt(0, dgitem)
End Sub

-John Oakes
 
G

Guest

john,

that worked great - thanks!

a few things - tablecell.columnspan allows you to set how "wide" the header
row will be and it may be a better idea to use the tableheadercell rather
than the normal tablecell.

spammy
 
J

John Oakes

Thanks. I do use columnspan and tableheadercell depending on the situation.
I was just giving a very simple example for demonstration purposes. Glad it
helped!

-John Oakes
 
G

Guest

oh - i posted that for group archive purposes just in case anyone else did a
search. i didnt doubt that you knew what what going on!

Spammy
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top