New to Telerik UI for WinForms? Download free 30-day trial

Create pop-up user control for row editing

Product Version Product Author Last modified
2016.2.608 RadGridView for WinForms Stefan Stefanov June, 2016

HOW-TO
Create a UserControl, that pops up underneath the current row after clicking "Edit" button. The UserControl provides allows editing the row.
 
SOLUTION
Let's start with creating the UserControl. There you can add the some controls that will help you to edit the cells in the grid. In our case we have added RadTextBox, RadDateTimePickerand RadButton. That is all you need to do in the UserControl. Perhaps you can modify some of these controls' properties (i.e. NullDate/ MinDate for RadDateTimePicker)

Then in your main form add a RadGridView, subscribe to its CreateCellevent and populate the grid. In our case it is manually populated by using our BingGrid() method, where two GridViewTextBoxColumnsand one GridViewDateTimeColumn are added. The first text box column is going to be used for storing our "Edit" button, and the other two respectively for storing the grid cells values.

Now we have to use our CustomCellclass which is going to be used in the first text box column. For this purpose we are creating a descendant of GridDataCellElementclass where we add two fields - one for RadDropDownButton(which is going to be our "Edit" button) and one for our UserControl. Then override the CreateChildElements() method, where you have to instantiate RadDropDownButton, manage its properties by your discretion and add it as a child of the CustomCell

Afterwards create a custom method (in this case CreateDropDownButton()), which returns RadMenuHostItem, that hosts an instance of the UserControl. The returned value is added to the items collection of RadDropDownButtonin CreateChildElements() method. In this method we also subscribe to RadDropDownButton'sclick event and for our saveButton's(from the user control) click event. 

The RadDropDownButton'sclick event is used to retrieve the values from the cell into the user controls' textbox and date time picker respectively.

The saveButton`s click event is used to set the values from these controls, back into the grid cells.

You can download a complete VB and C# project from the following link.

In this article
Not finding the help you need? Improve this article