Solved

How to add a second line to a datagrid footer

Posted on 2006-07-13
11
353 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
Independent Software Vendors: 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!

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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