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

Using a GridViewCommandColumn to populate other cells

1 Answer 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryan O'Neill
Top achievements
Rank 1
Ryan O'Neill asked on 31 Mar 2010, 02:55 PM
Hi,

I have a gridview with most of the data being read only as it depends on a key column. I'd like to have a GridViewCommandColumn that the user can click on, go to another winform and get back a number of values. These values should then be inserted into the new/edited row.

For example, the button might pop up a product search where I search for a product and when found, return the product name (read only) and product code (editable) to the gridview.

Have you any guidance on this? I tried searching the forums but the search falls over on 'GridViewCommandColumn'.

Edit: I've got the CommandCellClick event working and this works well within the grid if I used the code below, however, it does not work for new rows being added using the 'click here to add a new row' mechanism. The CommandCellClick event still fires and the value assignment does not cause an error, but it does not take effect either.

        cell.RowInfo.Cells("MyProductDescription").Value = "abcdef"
        cell.Value = Now.ToString() ' This also works, except when the row is a 'new' row added by the UI.

Thanks in advance

Ryan

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 06 Apr 2010, 09:45 AM
Hello Ryan O'Neill,
 
In the current edition of RadGridView the new row has related data row objects and editing new row cell values will not change the referenced data row. Currently you can use this code snippet:
 

void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    GridViewCellEventArgs args = e as GridViewCellEventArgs;
    if (args != null)
    {
        GridViewRowInfo editRow = args.Row;
        if (args.Row is GridViewNewRowInfo)
        {
            editRow = ((GridViewNewRowInfo)args.Row).DataRowInfo;
        }
 
        if (editRow != null)
        {
            editRow.Cells["CustomerID"].Value = 1111;
            editRow.Cells["ContactName"].Value = 1111;
            editRow.Cells["CompanyName"].Value = 1111;
 
        }
    }
}
 

In Q1 2010 SP1 we will handle this logic internally and additional code for new row will not be needed in the  CommandCellClick handler. SP1 release will be available for download very soon.

 

Sincerely yours,

Julian Benkov
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Ryan O'Neill
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or