8 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 10:52 AM
Hello David,
you need to use teh ViewCellFormatting event. See code below.
hope that helps, but let me know if you need anyhting else
Richard
you need to use teh ViewCellFormatting event. See code below.
Private
Sub
RadGridView1_ViewCellFormatting(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.WinControls.UI.CellFormattingEventArgs)
Handles
RadGridView1.ViewCellFormatting
If
TypeOf
e.CellElement
Is
Telerik.WinControls.UI.GridSummaryCellElement
Then
e.CellElement.TextAlignment = ContentAlignment.MiddleRight
End
If
End
Sub
hope that helps, but let me know if you need anyhting else
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 09:59 PM
Hello,
How did this go for you? If it is all fine now, please mark as answer so others can find the solution too. If you need more help, just let me know.
thanks
Richard
How did this go for you? If it is all fine now, please mark as answer so others can find the solution too. If you need more help, just let me know.
thanks
Richard
0
hkdave95
Top achievements
Rank 2
answered on 02 Dec 2010, 07:57 AM
Hi Richard
Thank you very much for the reply.
Unfortunately this did not work for me. The column summary is still centered.
I am using the latest internal build.
Any other ideas?
Kind Regards
David
Thank you very much for the reply.
Unfortunately this did not work for me. The column summary is still centered.
I am using the latest internal build.
Any other ideas?
Kind Regards
David
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Dec 2010, 08:45 AM
Hello,
Richard suggestion is the way to go on this one,
Please take a look at the following example:
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Richard suggestion is the way to go on this one,
Please take a look at the following example:
using
System;
using
System.ComponentModel;
using
System.Drawing;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
private
RadGridView radGridView1;
public
Form1()
{
InitializeComponent();
this
.Controls.Add(radGridView1 =
new
RadGridView());
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.ViewCellFormatting +=
new
CellFormattingEventHandler(radGridView1_ViewCellFormatting);
radGridView1.Dock = DockStyle.Fill;
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
var summaryItem =
new
GridViewSummaryItem(
"ValueToEnter"
,
"Values: {0}"
, GridAggregateFunction.Sum);
var summaryRow =
new
GridViewSummaryRowItem(
new
[] { summaryItem });
radGridView1.SummaryRowsBottom.Add(summaryRow);
radGridView1.DataSource =
new
TestsCollection();
}
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridSummaryCellElement)
{
e.CellElement.TextAlignment = ContentAlignment.BottomRight;
}
}
}
public
class
Test
{
public
int
ValueToEnter
{
get
;
set
;
}
public
int
CalculatedValue
{
get
;
set
;
}
}
public
class
TestsCollection : BindingList<Test>
{
public
TestsCollection()
{
for
(
int
i = 0; i < 3; i++)
{
this
.Add(
new
Test
{
ValueToEnter = i,
CalculatedValue = 0
});
}
}
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
hkdave95
Top achievements
Rank 2
answered on 02 Dec 2010, 09:49 PM
Hi
This is great! My columns are now right justified...
BUT. They have lost their FormatString formatting of "{0:C}".
NB: I am creating the SumarryRowBottom @ design time through the property editor.
Any ideas?
Kind Regards
David
This is great! My columns are now right justified...
BUT. They have lost their FormatString formatting of "{0:C}".
NB: I am creating the SumarryRowBottom @ design time through the property editor.
Any ideas?
Kind Regards
David
0
Richard Slade
Top achievements
Rank 2
answered on 02 Dec 2010, 10:08 PM
Hi David,
Have a check to see if the format is still there in the designer editor. I added a summary row to an existing grid, and added the text align property and it's showing up fine. Failing that, I'd remove and re-add the summary row again.
This is how it looks in my designer file
and attached is a screenshot
Hope this helps
Richard
Have a check to see if the format is still there in the designer editor. I added a summary row to an existing grid, and added the text align property and it's showing up fine. Failing that, I'd remove and re-add the summary row again.
This is how it looks in my designer file
'RadGridViewDynamicSummary1
'
GridViewSummaryItem1.Aggregate = Telerik.WinControls.UI.GridAggregateFunction.Sum
GridViewSummaryItem1.FormatString =
"{0:C}"
GridViewSummaryItem1.Name =
"Income"
Me
.RadGridViewDynamicSummary1.MasterTemplate.SummaryRowsBottom.Add(
New
Telerik.WinControls.UI.GridViewSummaryRowItem(
New
Telerik.WinControls.UI.GridViewSummaryItem() {GridViewSummaryItem1}))
Me
.RadGridViewDynamicSummary1.Name =
"RadGridView1"
Me
.RadGridViewDynamicSummary1.Size =
New
System.Drawing.Size(456, 311)
Me
.RadGridViewDynamicSummary1.TabIndex = 0
Me
.RadGridViewDynamicSummary1.Text =
"RadGridView1"
and attached is a screenshot
Hope this helps
Richard
0
hkdave95
Top achievements
Rank 2
answered on 02 Dec 2010, 10:42 PM
Hi Richard
Thanks for the quick response.
However, I posted rather prematurely. It seems that the formatting on the SummaryRowBottom is OK.
It is the FormatString on the column itself that is not working.
i.e. in your screen shot the Income column would need a format string of "{0:C}" to show the pound sign and 2 decimal places.
Kind Regards
David
Thanks for the quick response.
However, I posted rather prematurely. It seems that the formatting on the SummaryRowBottom is OK.
It is the FormatString on the column itself that is not working.
i.e. in your screen shot the Income column would need a format string of "{0:C}" to show the pound sign and 2 decimal places.
Kind Regards
David
0
Richard Slade
Top achievements
Rank 2
answered on 02 Dec 2010, 10:56 PM
Hi David,
you just need to add this somewhere after creating the columns:
for example, if you are creating them manually, directly after creating the column, or if you are auto creating the columns, in the DataBindingComplete event
hope that helps, but let me know if you have any more problems
Richard
you just need to add this somewhere after creating the columns:
Me
.RadGridView1.Columns(
"Income"
).FormatString =
"{0:C}"
for example, if you are creating them manually, directly after creating the column, or if you are auto creating the columns, in the DataBindingComplete event
Private
Sub
RadGridViewDynamicSummary1_DataBindingComplete(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.GridViewBindingCompleteEventArgs)
Handles
RadGridViewDynamicSummary1.DataBindingComplete
Me
.RadGridViewDynamicSummary1.Columns(
"Income"
).FormatString =
"{0:C}"
End
Sub
hope that helps, but let me know if you have any more problems
Richard