Combobox in gridview

4 posts, 0 answers
  1. Niklas
    Niklas avatar
    8 posts
    Member since:
    Sep 2014

    Posted 17 Sep 2014 Link to this post

    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? :)
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Sep 2014 Link to this post

    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.
     
  3. Niklas
    Niklas avatar
    8 posts
    Member since:
    Sep 2014

    Posted 19 Sep 2014 in reply to Dimitrina Link to this post

    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
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Sep 2014 Link to this post

    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.
     
Back to Top