This is a migrated thread and some comments may be shown as answers.

Showing sum of a coulmn

3 Answers 371 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tooraj
Top achievements
Rank 1
Tooraj asked on 21 Oct 2010, 01:55 PM
Hello,
1. I want to show sum of a coulmn of RadGridView in a text box. How do I must do this?
2. Suppose that there are 3 tables: Table1(PK1), Table2(FK1,FK2) and Table3(PK2).
the Table2  has equivalend ID from Table1 and Table2(One to many relation).
I've downloaded the ExCheckedListBox from CodeProject website. the ExCheckedListBox  data source is Table1. I want the Items which are in ExCheckedListBox to be checked only if they are in Table2.
link:http://www.codeproject.com/KB/combobox/ExCheckedListBox.aspx
Table1:
ID1    Name
1    Name1
2    Name2
3    Name3
Table 3:
ID2   City
1    City1
2    City2
3    City3

Table2:
ID1    ID2
1        1
1        2
1        3

ExCheckedListBox Items:
Name1    Name2    Name3
Only "Name1" must be chcked when user navigate through records of Table1 in a RadGridView object.
Please help me.

3 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 21 Oct 2010, 02:37 PM
Hi,

You can add a group summary row, then hide it and grab the text from it.
This should do it.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' Add in some rows
    Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("A"))
    Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("B"))
    Me.RadGridView1.MasterTemplate.AllowAddNewRow = False
    Me.RadGridView1.Rows.Add("1", "B1")
    Me.RadGridView1.Rows.Add("2", "B2")
    Me.RadGridView1.Rows.Add("3", "B1")
    Me.RadGridView1.Rows.Add("4", "B2")
    ' Add a summary row
    Dim summary As New GridViewSummaryRowItem()
    summary.Add(New GridViewSummaryItem("A", "{0} is the total of A", GridAggregateFunction.Sum))
    Me.RadGridView1.SummaryRowsBottom.Add(summary)
    ' hide the summary row and show it in a textbox
    Me.RadTextBox1.Text = Me.RadGridView1.MasterView.SummaryRows(0).Cells(0).Value.ToString()
    Me.RadGridView1.MasterView.SummaryRows(0).IsVisible = False
End Sub

hope that helps
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 21 Oct 2010, 05:44 PM
Hello guys,

For the first part i agree with Richard, but if the value changes then you have no way of updating the textbox.
This is why i would suggest registering to the GroupSummaryEvaluate event and getting the new value from there, like so:

radGridView1.GroupSummaryEvaluate += new GroupSummaryEvaluateEventHandler(radGridView1_GroupSummaryEvaluate);
var summaryItem = new GridViewSummaryItem();
summaryItem.FieldName = "Id";
summaryItem.Aggregate = GridAggregateFunction.Sum;
var summaryRow = new GridViewSummaryRowItem();
summaryRow.Add(summaryItem);
radGridView1.SummaryRowsTop.Add(summaryRow);
radGridView1.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Top;
 
 
void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    var value = e.Value;
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Alexander
Telerik team
answered on 26 Oct 2010, 04:36 PM
Hello Tooraj,

I agree with Richard and Emanuel that you can use summary rows and customize their evaluation using the GroupSummaryEvaluate event. Please let us know if this has helped you to achieve your scenario.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Tooraj
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or