Solved

How to add a second line to a datagrid footer

Posted on 2006-07-13
11
349 Views
Last Modified: 2012-06-21
Hi everyone, I am working on my first VB .Net application and one of my tasks is to add a second line in the footer of a datagrid.  On this line they want a previously calculated field to show up under one of the columns.  Can you please show me how to add this second line and how to line the fields up under specific columns.  
 
FOOTER

TOTAL | TOTAL | TOTAL               | TOTAL                   | TOTAL                   | TOTAL
                                                     TEXT for TOTAL2       VALUE FOR TOTAL2


Here is the code in the datagrid1_itemcreated procedure that creates the first line of the footer:

If (e.Item.ItemType = ListItemType.Footer) Then

            e.Item.Cells(2).Text = "Subtotal"
            e.Item.Cells(2).HorizontalAlign = HorizontalAlign.Right

            e.Item.Cells(3).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(3).Text = Format(intTotal1, "$###,###,###,##0.00")

            e.Item.Cells(5).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00")

            e.Item.Cells(6).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(6).Text = Format(intTotal3, "$###,###,###,##0.00")

            e.Item.Cells(7).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(7).Text = Format(intTotal4, "$###,###,###,##0.00")

            e.Item.Cells(8).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(8).Text = Format(intTotal5, "$###,###,###,##0.00")
           
        End If

Thank you,
Paul
0
Comment
Question by:paulmena
  • 7
  • 4
11 Comments
 
LVL 10

Expert Comment

by:vadim63
ID: 17100594
e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00") &  vbCrLf
e.Item.Cells(5).Text += "TEXT for TOTAL2"
0
 

Author Comment

by:paulmena
ID: 17101547
Hi vadim63, thanks for taking a look.  I tried it 2 ways but it doesn't seem to be working the way I expected it would.  

1.added the vbCrLf like this:

e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00") & vbCrLf
e.Item.Cells(5).Text += "TEXT for TOTAL2"

what this did is it overwrote the value that is in the first row total without adding another line.

2. added the vbCrLf to the end of the first row:

            e.Item.Cells(2).Text = "Subtotal"
            e.Item.Cells(2).HorizontalAlign = HorizontalAlign.Right

            e.Item.Cells(3).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(3).Text = Format(intTotal1, "$###,###,###,##0.00")

            e.Item.Cells(5).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00")

            e.Item.Cells(6).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(6).Text = Format(intTotal3, "$###,###,###,##0.00")

            e.Item.Cells(7).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(7).Text = Format(intTotal4, "$###,###,###,##0.00")

            e.Item.Cells(8).HorizontalAlign = HorizontalAlign.Right
            e.Item.Cells(8).Text = Format(intTotal5, "$###,###,###,##0.00") & vbCrLf

            e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00")
            e.Item.Cells(5).Text += "TEXT for TOTAL2"

This had the same result as #1.  It overwrote the total on the first row without adding an additional line.

Paul



0
 
LVL 10

Expert Comment

by:vadim63
ID: 17101617
That's because of your row heght is to small. I guess there's 16 by default. Set it higher. (let's say 32)
0
 
LVL 10

Expert Comment

by:vadim63
ID: 17101646
I don't remember the datagrids. Now I'm using DataGridView. There's a property "Autosize Row Height".
0
 

Author Comment

by:paulmena
ID: 17101953
vadim63, I changed the row height to 100 and the value on the first row is still getting overwritten. No line as been added.

Paul  
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 10

Expert Comment

by:vadim63
ID: 17102169
What control is that? Where did you get "e.Item.Cells ..."? Is that DataGrid, or DataGridView?
0
 

Author Comment

by:paulmena
ID: 17102468
Its from a DataGrid.  

This is the beginning of the procedure.
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated

        If (e.Item.ItemType = ListItemType.Footer) Then

            e.Item.Cells(2).Text = "Subtotal"
            e.Item.Cells(2).HorizontalAlign = HorizontalAlign.Right



0
 
LVL 10

Expert Comment

by:vadim63
ID: 17102537
O God! You're talking about web application.
0
 
LVL 10

Accepted Solution

by:
vadim63 earned 500 total points
ID: 17102721
OK, If we're talking about web grid, your code should be like this:

e.Item.Cells(5).Text = Format(intTotal2, "$###,###,###,##0.00") &  "<br>" & "TEXT for TOTAL2"
0
 

Author Comment

by:paulmena
ID: 17102754
Hi vadim63, that worked perfectly.  Thank you for helping me out.

Paul
0
 
LVL 10

Expert Comment

by:vadim63
ID: 17102777
Thank you for the points.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now