How to get the sum of an particular column of telerik ListView?

195 Views Asked by At

hi can anyone help me with this i want to convert this webform code to used with telerik control,

{
    int i = 0;
    int j = 0;
    int k = 0;
    i = 0;
    j = 0;
    k = 0;

    try
    {
        j = ListView1.Items.Count;
        for (i = 0; i <= j - 1; i++)
        {
            k = k + Convert.ToInt32(ListView1.Items[i].SubItems[5].Text);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    return k;
}

basically i need to get the sum of a particluar column from a list view which is in telerik so if anyone can help me out please do help Thanks in Advance

2

There are 2 best solutions below

0
somesh tripathi On BEST ANSWER

ok so here is the solution itself thanks @checho for helping me out really appreciate your help

  foreach (ListViewDataItem item in radListView1.Items)
            {
                //k += (int)item["Column 1"].ToString();
                //this code helped me 

                k += Convert.ToInt32(item["Column 1"].ToString());
            }
2
checho On

If you are using RadListView from the Telerik UI for Winforms suite, here is how to access the values of the items in the different cells in the control:

        int i = 0;
        foreach (ListViewDataItem item in radListView1.Items)
        {
            i += (int)item["YourColumnName"];
        }