Custom Row Edit in RadGrid for winforms

12 posts, 1 answers
  1. muthanna
    muthanna avatar
    2 posts
    Member since:
    Jun 2011

    Posted 09 Jun 2011 Link to this post

    Hello, please I've been searching for two days for this & couldn't find it ...
    I'm trying to do something like this example :
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultvb.aspx

    but i want it in windows form application ... please help

    I am not sure if the properties for the ASP rad grid are the same for windows forms rad grid ... like this line
    RadGrid1.MasterTableView.EditMode = GridEditMode.EditForms
    and
    RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace

    Please help as soon as you can :S
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 15 Jun 2011 Link to this post

    Hello muthanna,

    Thank you for writing.

    RadControls for ASP.NET AJAX and for WinForms are different suites and they have different API. However, in regards to your question, we do not have such a functionality out of the box, but we do have a Knowledge Base article, which demonstrate how you can achieve similar functionality. Please refer to this link, where you can find the mentioned article and a sample implementation.

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Kind regards,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. muthanna
    muthanna avatar
    2 posts
    Member since:
    Jun 2011

    Posted 16 Jun 2011 Link to this post

    Thanks, I've seen this Article before and it was a bit helpful, however i went to another approach by just putting a form outside the grid by each Command click.

    anyway thanks :)
  5. RJ
    RJ avatar
    386 posts
    Member since:
    Oct 2006

    Posted 11 Nov 2012 Link to this post

    Does this work also when you click add new row?
    My grid is for preview only so it wont show other colums but those columns has entry on form to be shown. So during add and edit it will have extra data to be inputed which are not shown on the grid, Is this possible?
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 14 Nov 2012 Link to this post

    Hi,

    The example will work for the new row as well. The only think that you should change if you are using the latest version is the following line of code in the save_Click event handler:
    //add new row
    if (this.RowInfo is GridViewNewRowInfo)
    {
        //this.GridControl.Rows.Add(new object[] { null, textBox.Text, dateTimePicker.Value });
        ((GridViewNewRowInfo)this.RowInfo).EndAddNewRow();
    }

    As to filling the data in non-visible columns, you should be able to do that. Simply extend the user control as needed and populate the hidden column values respectively. 

    I hope this helps.
     
    Regards,
    Stefan
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  7. RJ
    RJ avatar
    386 posts
    Member since:
    Oct 2006

    Posted 16 Nov 2012 Link to this post

    Hi Stefan,

    Thanks for your response but I cant seem to make the user control show whenever I click the add a new row on the sample file. I still need to click the "Click For Edit" button to show the user control and when I do save it, the row doubles up. Sorry I'm new to winform for my work is always on web app.

    If you could give more info on how to show user control on add a new row click, it would be very much appreciated and also a delete column for deleting row..

    Lastly if you have a button on the grid(real button column not the raddropdownbuttonelement) that pops user control(mdi child) that can be move, it would be much better. Same goes to add a new row, it will pop user control(mdi child) as well.

    Thanks in advance and hope to hear from you soon,
    RJ
  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 21 Nov 2012 Link to this post

    Hello RJ,

    I am not quite sure that I understand whether you want or not the button "Click here to edit" to appear in the new row. With the current solution it will appear and the user can click the button to show the user control (see attached video). You just need to take the solution from the KB article, change the references to the latest ones and to avoid row doubling, use the code that I provided in my previous post.

    If you do not want to show the custom cell in the new row, remove the check for GridViewNewRowInfo from the CreateCell event handler.

    To show the user control when the new row is clicked, you can should make the button in the CustomCell public (so we can access it) and use the MouseDown event of the control to perform a click:
    void radGridView1_MouseDown(object sender, MouseEventArgs e)
    {
        RadElement clickedElement = radGridView1.ElementTree.GetElementAtPoint(e.Location);
        Console.WriteLine(radGridView1.ElementTree.GetElementAtPoint(e.Location));
        if ((clickedElement is GridCellElement && ((GridCellElement)clickedElement).RowInfo is GridViewNewRowInfo) || clickedElement is GridNewRowElement)
        {
            CustomCell cell = (CustomCell)radGridView1.TableElement.GetCellElement(radGridView1.MasterView.TableAddNewRow, radGridView1.Columns["Edit"]);
            cell.button.PerformClick();
        }
    }

    As to the delete column, I am not sure how it should look like. You can add GridViewCommandColumn and use it to delete the row.

    About the button, it can be easily achieved again with a command column. The subject discussed in this thread is about the custom row that pops up when the drop down button is clicked. If you have questions other that does not concern the initial topic of a certain thread, please address them in a corresponding thread, or if such is missing in a new thread.

    Attached is a modified version of the KB, where the discussed changes are applied.

    I hope this helps.
     
    Greetings,
    Stefan
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  9. Olivier
    Olivier avatar
    1 posts
    Member since:
    Oct 2012

    Posted 23 Nov 2012 Link to this post

    Hi,

    I noticed that using a RadCommandColumn (instead of a RadTextBoxColumn like in your example) as the custom cell could lead to strange behaviors when grouping.
    GridViewCommandColumn editButtonColumn = new GridViewCommandColumn();

    For example : grouping by "DateTimeColumn".
    Please modify the CreateCell method because the application could crash when trying to group.

    void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {  
         if (e.Column != null && e.Column.Name == "Edit" && (e.Row is GridDataRowElement || e.Row is GridNewRowElement))
         {
                 e.CellType = typeof(CustomCell);
                 e.CellElement = new CustomCell(e.Column, e.Row);
          }
    }


    Regards,

    Olivier.
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 28 Nov 2012 Link to this post

    Hi Olivier,

    Thank you for writing.

    The exception is not caused because you changed the type of the column, it is because the Column is null when grouping is performed. Adding a check for null will solve this case:
    void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.Column != null)
        {
            if (e.Column.Name == "Edit" && (e.Row is GridDataRowElement || e.Row is GridNewRowElement))
            {
                e.CellType = typeof(CustomCell);
                e.CellElement = new CustomCell(e.Column, e.Row);
            }
        }
    }

    I hope this helps.
     
    Greetings,
    Stefan
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  11. Chandrak
    Chandrak avatar
    12 posts
    Member since:
    Oct 2012

    Posted 09 Jul 2015 Link to this post

    Hi,

     I've used this approach in my demo application. Now I want to delete row (delete button added as custom cell as described) can you post some code to do so? Say deleteButton_Click() {   ???? }

  12. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Jul 2015 Link to this post

    Hello Chandrak,

    Why don't you just add a GridViewCommandColumn to your grid and upon button click to delete the respective row. Here you can find the column documentation: http://www.telerik.com/help/winforms/gridview-columns-gridviewcommandcolumn.html?

    Regards,
    Stefan
    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
  13. Chandrak
    Chandrak avatar
    12 posts
    Member since:
    Oct 2012

    Posted 10 Jul 2015 in reply to Stefan Link to this post

    Thanks Stefan,

     I've found solution. Prefer old way.

     Regards

    Chandrak

Back to Top
UI for WinForms is Visual Studio 2017 Ready