Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

extra header in datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
saleek - 17 Jan 2005 11:17 GMT
I was wondering if there is a way I can add an extra header to a datagrid?

I found this solution on the internet - but it seems quite old and didn't
work for me.

http://www.dotnet247.com/247reference/msgs/13/69744.aspx

It recommends the following:

Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.PreRender
   Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)
   Dim mycell As New TableCell
   mycell.ColumnSpan = 1 'Set it to the colspan that you want
   mycell.Text = "PRESS RADIO TV"
   dgitem.Cells.Add(mycell)
   DataGrid1.Controls(0).Controls.AddAt(0, dgitem)
End Sub

But I get an error:

Specified argument was out of the range of valid values. Parameter name:
index

I appreicate your help,


KS
Mike McIntyre [MVP] - 17 Jan 2005 16:21 GMT
Hi Saleek,

Since you posted to the Windows Forms newsgroup are you looking for a
solution that adds and extra header to a Windows Forms DataGrid?

If so the reason the example did not work is because it is for a web forms
DataGrid.

Signature

Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

>I was wondering if there is a way I can add an extra header to a datagrid?
>
[quoted text clipped - 23 lines]
>
> KS
saleek - 17 Jan 2005 16:39 GMT
Mike,

Thanks for your reply. I was asked by a Developer Engineer to post it here -
but i did want a solution for an asp.net webform datagrid.

Anyway, I have been given a solution. For the benefit of anyone else wishing
to know, it is doen like so:

Private Sub DataGrid1_ItemDataBound _
       (ByVal sender As Object, _
       ByVal e As _
       System.Web.UI.WebControls.DataGridItemEventArgs) _
       Handles DataGrid1.ItemDataBound
       If e.Item.ItemType = ListItemType.Header Then
           Dim dgItemHeader As New DataGridItem _
           (0, 0, ListItemType.Header)

           e.Item.Attributes.Add("style", "background:#C0D3E9")

           Dim fcell As TableCell
           Dim i As Integer
           For i = 0 To 3
               fcell = New TableCell
               fcell.ColumnSpan = 3

               Select Case i
                   Case 0
                       fcell.ColumnSpan = 2
                       fcell.Text = ""
                   Case 1
                       fcell.Text = "Press"
                   Case 2
                       fcell.Text = "Radio"
                   Case 3
                       fcell.Text = "Tv"
               End Select
               fcell.HorizontalAlign = HorizontalAlign.Center
               dgItemHeader.Cells.Add(fcell)
           Next i

           DataGrid1.Controls(0).Controls.AddAt(0, dgItemHeader)
       End If
   End Sub

This code creates an extra header on top of the default one and adds 1 cell
which spans 2 columns and adds 3 other cells which span 3 columns each.

Regards,

KS

> Hi Saleek,
>
[quoted text clipped - 31 lines]
> >
> > KS

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.