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

Automatically Adding a new row in RadGridView

1 Answer 174 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tanya
Top achievements
Rank 1
Tanya asked on 03 May 2013, 12:18 PM
I'm working on a windows application where I've implemented the telerik controls.

I have a  radgridview , and I've added 4 columns to it during the design time.
They are

GridViewComboBoxColumn
GridViewTextColumn
another two GridViewComboboxColumn.

The first GridViewComboBox column is bound to a datasource and it displays all the desired results.
The last two GridViewComboBox's are bound to string of arrays.

I've added around three blank rows to the grid.

So when the user has entered the details to the first three rows, I wanted a new blank row to be added automatically.

On which event should I write my code to add a new blank row automatically?
How to know that the user has finished adding details to the first three rows?

 Please help me know how to do it.

Any help on this will be really appreciated.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 08 May 2013, 08:33 AM
Hi Tanya,

Perhaps you can use the CellValueVhanged event of RadGridView, which will be triggered every time the users changes a cell value. In the event handler, you can check the previous rows cells for values and if they a have such, add a new row. Here is a sample to get you started:
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    int index = e.RowIndex;
    int count = 0;
 
    bool foundEmptyCell = false;
 
    while (index >= 0 && count < 3)
    {
        foreach (GridViewCellInfo cell in radGridView1.Rows[index].Cells)
        {
            if (cell.Value == null)
            {
                foundEmptyCell = true;
                break;
            }
        }
 
        count++;
        index--;
    }
 
    if (!foundEmptyCell)
    {
        radGridView1.Rows.AddNew();
    }
}

I hope that you find this information useful.

All the best,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
Tanya
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or