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

Combobox in gridview

3 Answers 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Niklas
Top achievements
Rank 1
Niklas asked on 17 Sep 2014, 11:25 AM
I have a RadGridView with AutoGenerateColumns="true". Now i need to change one of the columns from being a plain column to a comboboxcolumn in code behind. What is the best way to do this? 

So instead of displaying a grid with say 3 columns:

[id] [PersonId] [PersonName]

i want 2 columns and catch the column with PersonName an replace it with a comboboxcolumn so i can pick any row in the column. The comboboxvolumn sould display the [PersonName] but the value should be the [PersonId].

Also the grid is used to display various tables so i cant use a predefined template i think?

I dont know if this makes sense? :)

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Sep 2014, 02:48 PM
Hi,

In order to replace the default auto-generated column with GridViewComboBoxColumn, you should subscribe for the AutoGeneratingColumn event. Once it is raised for the column, you can replace e.Column with a new one. In case you prefer to not create a new column, you can also directly define a CellTemplate for the already generated column (e.Column).

You can learn more about how to configure GridViewComboBoxColumn properly in our online documentation here: ComboBox Column.

Regards,
Dimitrina
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Niklas
Top achievements
Rank 1
answered on 19 Sep 2014, 10:58 AM
That is how far i got this morning. By using the AutoGeneratingColumn event. It seems to be the way to go. Is it possible to define just a celltemplate inside the GridView and how do i do this or what is the best way to do this? Also how do i assign the template. I guess it should be bound to two different colums? On for value & one for displaytext? Or do i need to define a whole column but only use the celltemplate from it? Im new to this so there might be a fiew dumb questions here! ;)

/Niklas
0
Dimitrina
Telerik team
answered on 22 Sep 2014, 02:46 PM
Hi Niklas,

You can place everything you wish in the DataTemplate you will use as a CellTemplate. For example, you can place two different controls and bind their content accordingly.
You can check the following article in our online documentation suggesting how to do so:
Setting CellTemplate and CellEditTemplate.
In the article the CellTemplate is assigned in XAML, however, you can also assign it
 to the e.Column as the AutoGeneratingColumn event is raised.


Regards,
Dimitrina
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Niklas
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Niklas
Top achievements
Rank 1
Share this question
or