473,513 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Carriage return

I am new to C# and I am writing a small Windows app that consists of a Label
and Button. I've written code that displays the following in the Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx
Feb 12 '06 #1
8 9291
Hi,

1. Your header doesn't show because in the line:

label1.Text = "---- ----\n";

you erase the previous value you assigned to label1.Text. The correct code
is:

label1.Text += "---- ----\n"; // '+' was missing

2. Showing data in the grid takes a little more, check this doc:

http://support.microsoft.com/kb/315786/EN-US/

Regards - Octavio

"Jlaz" <Xb*******@msn.com> escribió en el mensaje
news:em*************@TK2MSFTNGP09.phx.gbl...
I am new to C# and I am writing a small Windows app that consists of a
Label and Button. I've written code that displays the following in the
Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx

Feb 12 '06 #2
Hi Jlaz,

In addition to Octavio's answer, you should use \r\n for line breaks, not just \n. Some controls won't recognize \n as a line break.
On Sun, 12 Feb 2006 08:58:21 +0100, Jlaz <Xb*******@msn.com> wrote:
I am new to C# and I am writing a small Windows app that consists of a Label
and Button. I've written code that displays the following in the Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx


--
Happy coding!
Morten Wennevik [C# MVP]
Feb 12 '06 #3
Hi,
I enjoyed the link http://support.microsoft.com/kb/315786/EN-US/. But I am
unable to understand the fundamentals behind it. How can class members are
automatically get displayed in Data Grid. I have also observed that only
those values get displayed, for which there exist get.

Thanks
Chakravarti Mukesh
"Octavio Hernandez" <oc*****************@gmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

1. Your header doesn't show because in the line:

label1.Text = "---- ----\n";

you erase the previous value you assigned to label1.Text. The correct code
is:

label1.Text += "---- ----\n"; // '+' was missing

2. Showing data in the grid takes a little more, check this doc:

http://support.microsoft.com/kb/315786/EN-US/
Regards - Octavio

"Jlaz" <Xb*******@msn.com> escribió en el mensaje
news:em*************@TK2MSFTNGP09.phx.gbl...
I am new to C# and I am writing a small Windows app that consists of a
Label and Button. I've written code that displays the following in the
Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a
second label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx


Feb 12 '06 #4
Why not use a ListView?

"Jlaz" <Xb*******@msn.com> wrote in message
news:em*************@TK2MSFTNGP09.phx.gbl...
I am new to C# and I am writing a small Windows app that consists of a
Label and Button. I've written code that displays the following in the
Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx

Feb 12 '06 #5
Hi Chakravarti,

Any object 'property' is shown. This means you can create objects or structs out of each line of your list

This code create a list of CostItem objects and stores it in an ArrayList.
The ArrayList is then bound to a DataGridView (Framework 2.0).
The DataGridView will detect the properties Rent and Year in the objects inside the ArrayList and will create necessary columns and headers.

The m behind the rent indicates that the number should be treated as decimal.

private void Form1_Load(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
list.Add(new CostItem(2004, 1200m));
list.Add(new CostItem(2005, 1260m));
list.Add(new CostItem(2004, 1323m));
list.Add(new CostItem(2004, 1389.15m));

dataGridView1.DataSource = list;
}
class CostItem
{
int iYear;
decimal dRent;

public int Year
{
get
{
return iYear;
}
}

public string Rent
{
get
{
// output the rent as currency
return dRent.ToString("c");
}
}

// Constructor
public CostItem(int y, decimal r)
{
iYear = y;
dRent = r;
}
}
--
Happy coding!
Morten Wennevik [C# MVP]
Feb 12 '06 #6
Excellent post, Morten!

Regards - Octavio
"Morten Wennevik" <Mo************@hotmail.com> escribió en el mensaje
news:op.s4u470suklbvpo@stone...
Hi Chakravarti,

Any object 'property' is shown. This means you can create objects or
structs out of each line of your list

This code create a list of CostItem objects and stores it in an ArrayList.
The ArrayList is then bound to a DataGridView (Framework 2.0).
The DataGridView will detect the properties Rent and Year in the objects
inside the ArrayList and will create necessary columns and headers.

The m behind the rent indicates that the number should be treated as
decimal.

private void Form1_Load(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
list.Add(new CostItem(2004, 1200m));
list.Add(new CostItem(2005, 1260m));
list.Add(new CostItem(2004, 1323m));
list.Add(new CostItem(2004, 1389.15m));

dataGridView1.DataSource = list;
}
class CostItem
{
int iYear;
decimal dRent;

public int Year
{
get
{
return iYear;
}
}

public string Rent
{
get
{
// output the rent as currency
return dRent.ToString("c");
}
}

// Constructor
public CostItem(int y, decimal r)
{
iYear = y;
dRent = r;
}
}
--
Happy coding!
Morten Wennevik [C# MVP]

Feb 12 '06 #7
Thanx guys,

Your answers worked for me. I'm making the switch from VB to C# any
recomendations?
"Jlaz" <Xb*******@msn.com> wrote in message
news:em*************@TK2MSFTNGP09.phx.gbl...
I am new to C# and I am writing a small Windows app that consists of a
Label and Button. I've written code that displays the following in the
Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx

Feb 12 '06 #8
Question 1 is the easier to answer :
label1.Text = "---- ----\n"; You forgot to use '+=' instead of '='

(I just suggest to make use of the 'System.Text.StringBuilder' class in
order to deal with text concatenation...)
To Question 2:
The are many ways to achieve this.
Have a look, for example, at the ListView.

Hope this helps...

Michel.
"Jlaz" <Xb*******@msn.com> a écrit dans le message de news:
em*************@TK2MSFTNGP09.phx.gbl...I am new to C# and I am writing a small Windows app that consists of a
Label and Button. I've written code that displays the following in the
Label:

---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69

I need it to display the heading as well without having to create a second
label to produce the "Year Rent":

Year Rent
---- ----
2004 $1,200.00
2005 $1,260.00
2006 $1,323.00
2007 $1,389.15
2008 $1,458.61
2009 $1,531.54
2010 $1,608.12
2011 $1,688.53
2012 $1,772.96
2013 $1,861.61
2014 $1,954.69
My Code is the following:
private void btnExecute_Click(object sender, System.EventArgs e)

{

int iYear = 2004, iFinalYear = 2014;

decimal mRent = 1200, mIncrease = 5.0m;
label1.Text = "Year Rent\r\n";

label1.Text = "---- ----\n";

while (iYear <= iFinalYear)

{

label1.Text += iYear + " " + mRent.ToString( "C") + "\n";

mRent *= (1 + mIncrease / 100);

mRent = Decimal.Round(mRent, 2);

iYear++;

}

}

Question1: How do I get the heading to show?

Question2: How can I display this same info in a Grid?

Thanx

Feb 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9258
by: Canes_Rock | last post by:
The information posted at: ...
2
4115
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the...
1
4557
by: chrissmith_76_Fed_Up_With_Spam | last post by:
Hello all, I am using Access 2002, with file format of Access 2000, and am experiencing a problem. I have a subform that is shown in datasheet view for users to edit data direct to a table. ...
2
2927
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
2
6142
by: David Cho | last post by:
I am using this expression \d+(,\s*\d+)* to allow only numbers and commas. But if there are carriage returns mixed, it is not validated. Is tehre a way to ignore all carriage returns? I...
11
8432
by: TheRain | last post by:
Hi, I am trying to append a carriage return to my string using the string builder class, but when I do this the string ends up containing "13". I tried this multiple ways like so ...
3
3370
by: Dinsdale | last post by:
I have an xml file that is read into an object using serialization. One of the objects has a string field called delimeter that I want to contain a carriage return. Instead of trying to include the...
0
1805
by: J.Marsch | last post by:
I am having a problem in which ASP.Net web services are corrupting my data. I know that my problem is related to the standard way of encoding carriage return linefeeds, so I need to figure out how...
11
12556
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.