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

RadGridView count of number rows with data filled

3 Answers 1038 Views
GridView
This is a migrated thread and some comments may be shown as answers.
A-Telerik-User
Top achievements
Rank 1
A-Telerik-User asked on 08 Aug 2019, 03:20 AM

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.

 

3 Answers, 1 is accepted

Sort by
0
A-Telerik-User
Top achievements
Rank 1
answered on 08 Aug 2019, 03:22 AM
Miss out a point. Data were filled manually without any binding involved.
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Aug 2019, 06:45 AM
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.
0
A-Telerik-User
Top achievements
Rank 1
answered on 13 Aug 2019, 06:00 AM
it works! thank you
Tags
GridView
Asked by
A-Telerik-User
Top achievements
Rank 1
Answers by
A-Telerik-User
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or