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

Custom Row Edit in RadGrid for winforms

11 Answers 419 Views
GridView
This is a migrated thread and some comments may be shown as answers.
muthanna
Top achievements
Rank 1
muthanna asked on 09 Jun 2011, 10:18 AM
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

11 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 15 Jun 2011, 07:59 AM
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.
0
muthanna
Top achievements
Rank 1
answered on 16 Jun 2011, 05:12 PM
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 :)
0
RJ
Top achievements
Rank 1
answered on 11 Nov 2012, 05:16 PM
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?
0
Stefan
Telerik team
answered on 14 Nov 2012, 11:02 AM
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.
0
RJ
Top achievements
Rank 1
answered on 16 Nov 2012, 07:54 PM
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
0
Stefan
Telerik team
answered on 21 Nov 2012, 11:10 AM
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.
0
Olivier
Top achievements
Rank 1
answered on 23 Nov 2012, 04:55 PM
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.
0
Stefan
Telerik team
answered on 28 Nov 2012, 12:39 PM
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.
0
Chandrak
Top achievements
Rank 1
answered on 09 Jul 2015, 06:40 AM

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() {   ???? }

0
Stefan
Telerik team
answered on 10 Jul 2015, 02:25 PM
Hello ,

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
0
Chandrak
Top achievements
Rank 1
answered on 10 Jul 2015, 03:00 PM

Thanks Stefan,

 I've found solution. Prefer old way.

 Regards

Chandrak

Tags
GridView
Asked by
muthanna
Top achievements
Rank 1
Answers by
Stefan
Telerik team
muthanna
Top achievements
Rank 1
RJ
Top achievements
Rank 1
Olivier
Top achievements
Rank 1
Chandrak
Top achievements
Rank 1
Share this question
or