Solved

How to add a second line to a datagrid footer

Posted on 2006-07-13
11
352 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 51
How do sunrise and sunset times change with altitude 14 46
Code enhancement 4 34
how to remove error in database 6 37
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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