RadGridView count of number rows with data filled

4 posts, 1 answers
  1. A-Telerik-User
    A-Telerik-User avatar
    5 posts
    Member since:
    Oct 2013

    Posted 07 Aug 2019 Link to this post

    Hi,

    There is a single gridview control place in my application winforms with default RowCount set to 5, where user allows to create new row of record more or less than that. For example there's possible to have situations where number of rows in grid is 10 but only 8 rows were filled with data. Is there any control build-in function which return me the number of rows with data filled directly? Not in good luck to find one either from online references.

    Thanking in advance.

     

  2. A-Telerik-User
    A-Telerik-User avatar
    5 posts
    Member since:
    Oct 2013

    Posted 07 Aug 2019 in reply to A-Telerik-User Link to this post

    Miss out a point. Data were filled manually without any binding involved.
  3. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3575 posts

    Posted 12 Aug 2019 Link to this post

    Hello,    

    According to the provided information, I suppose that you are using the approach demonstrated in this article: https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/unbound-mode

    In order to determine how many rows are used, you can iterate the cells for each row and check the value. I have prepared a sample code snippet for your reference:

    public RadForm1()
    {
        InitializeComponent();
     
        this.radGridView1.RowCount = 10;
        this.radGridView1.Columns.Add(new GridViewTextBoxColumn("A"));
        this.radGridView1.Columns.Add(new GridViewTextBoxColumn("B"));
        this.radGridView1.MasterTemplate.AllowAddNewRow = false;
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        int usedRows = 0;
        bool hasData = false;
        foreach (GridViewRowInfo row in this.radGridView1.Rows)
        {
            hasData = false;
            foreach (GridViewCellInfo cell in row.Cells)
            {
                if (cell.Value != null)
                {
                    hasData = true;
                    break;
                }
            }
            if (hasData)
            {
                usedRows++;
            }
        }
     
        this.Text = "Used Rows: " + usedRows;
    }

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  4. A-Telerik-User
    A-Telerik-User avatar
    5 posts
    Member since:
    Oct 2013

    Posted 13 Aug 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    it works! thank you
Back to Top