Automatically Adding a new row in RadGridView

2 posts, 0 answers
  1. Tanya
    Tanya avatar
    1 posts
    Member since:
    May 2013

    Posted 03 May 2013 Link to this post

    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.

  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 08 May 2013 Link to this post

    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.
Back to Top