?
Solved

How to add a second line to a datagrid footer

Posted on 2006-07-13
11
Medium Priority
?
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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