Add row get value problem

4 posts, 1 answers
  1. Chang
    Chang avatar
    7 posts
    Member since:
    Sep 2015

    Posted 12 Oct 2015 Link to this post

    Hi, I am new to Telerik and am currently developing a program for my company. I click on the "Click here to add a new row" button on the top and input the values for each column. Then I want to have the user press a "save" button and save these values to the Oracle database. I am unable to get the values for each column. I've came across many versions of this problem throughout my search, but I want the most up to date one that would allow me to get the new row values that I entered from "Click here to add a new row". Thanks! Both dr and currentRow.value return null.

     private void btSave_Click(object sender, EventArgs e)
            {
                GridViewRowInfo dr = this.gvUser.GridViewElement.CurrentRow as GridViewRowInfo;
                GridViewNewRowInfo currentRow = dr as GridViewNewRowInfo; 
                
                if (currentRow != null)
                {
                    string test = dr.Cells[1].Value.ToString();

                     test = currentRow.Cells[1].Valiue.Tostring();
                     test = dr.Cells[2].Value.ToString();
                     test = dr.Cells[3].Value.ToString();
                     test = dr.Cells[4].Value.ToString();
                     test = dr.Cells[5].Value.ToString();
                }
            }

  2. Chang
    Chang avatar
    7 posts
    Member since:
    Sep 2015

    Posted 12 Oct 2015 Link to this post

    I played around with it a bit more. So it seems I can't do anything with the values like with default value until I hit enter and have the values committed to the bottom rows.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chang
    Chang avatar
    7 posts
    Member since:
    Sep 2015

    Posted 12 Oct 2015 Link to this post

    New question, how do I loop through the collection of rows at the bottom from "click here to add a new row"? I want to loop through them so I can add all of them into the database at once.
  5. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 13 Oct 2015 Link to this post

    Hi Chang,

    Thank you for writing.

    In the first case, the row is already added to the grid and it is the last row so you can access it like this:
    private void radButton1_Click(object sender, EventArgs e)
    {
        var row = radGridView1.Rows[radGridView1.Rows.Count - 1];
    }

    Another approach would be to use the new row events. Detailed information is available here: New Row. As a general solution, you should consider using the RowsChanged event which will fire when something is changed in the grid. This way you will be able to update the database: Tracking changes in RadGridView.

    The following article show how you can iterate all rows in the grid: Iterating Rows.

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top