I have a RadGridView with a series of nested HierarchyChildTemplates each with defined GridViewDataColumns. Within one of the children we have enabled editing and would like to implement a RadComboBox as part of the CellEditTemplate/DataTemplate for a particular GridViewDataColumn. How do I go about binding the lookup values to the RadComboBox on edit within the child RadGridView and how do I have the current value, if existing, be the selected value from the bound lookup options. A snippet of the HierarchyChildTemplate is as follows where the RadComboBox named rcbCONSULTANTNAME is what I am trying to implement:
<
telerik:RadGridView.HierarchyChildTemplate
>
<
DataTemplate
>
<
telerik:RadGridView
ItemsSource
=
"{Binding ocContractData}"
x:Name
=
"rgvConracts"
IsReadOnly
=
"False"
CanUserDeleteRows
=
"True"
CanUserInsertRows
=
"True"
ShowInsertRow
=
"True"
CanUserSelect
=
"True"
RowEditEnded
=
"rgvConracts_RowEditEnded"
CellEditEnded
=
"rgvConracts_CellEditEnded"
AddingNewDataItem
=
"rgvConracts_AddingNewDataItem"
AutoGenerateColumns
=
"False"
ShowGroupPanel
=
"False"
Margin
=
"10,10,10,10"
VerticalAlignment
=
"Stretch"
HorizontalAlignment
=
"Stretch"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Project Contract ID"
UniqueName
=
"PROJECT_CONTRACT_ID"
IsVisible
=
"False"
/>
<
telerik:GridViewDataColumn
Header
=
"Project Phase ID"
UniqueName
=
"PROJECT_PHASE_ID"
IsVisible
=
"False"
/>
<
telerik:GridViewDataColumn
Header
=
"Contract"
DataMemberBinding
=
"{Binding CONTRACT_NAME, Mode=TwoWay}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
TextBox
Text
=
"{Binding CONTRACT_NAME, Mode=TwoWay}"
Loaded
=
"Editor_Loaded"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Consultant"
DataMemberBinding
=
"{Binding CONSULTANT_NAME, Mode=TwoWay}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadComboBox
Name
=
"rcbCONSULTANTNAME"
DisplayMemberPath
=
"CONSULTANT_NAME"
SelectedValuePath
=
"CONSULTING_ID"
SelectedValue
=
"{Binding CONSULTANT_NAME}"
>
</
telerik:RadComboBox
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
.......
.............
Thanks,
Aaron
14 Answers, 1 is accepted
Can you please check if the GridViewComboBoxColumn isn't more suitable for your scenario.
We can go both ways - using the combo column , or using a regular column with a modified cell edit template. ( I would recommend the GridViewComboBox column approach)
Just let me know which way to go and I will assist you further with some sample code.
Best wishes,
Pavel Pavlov
the Telerik team
Thanks for the quick response. I don't think I was able to implement a GridViewComboBox within the edit template; however, if that's best practice then that's what we shall do. I look forward to your response.
Aaron
Could you give some sample codes on regular column with a modified cell edit template. I tried the GridViewComboBox approach but I dont have acces to the HierarchyChildTemplates in my code behind. The HierarchyChildTemplates is pretty large so I dont want to recrate the template in my code behind.
Thanks
The attached example demonstrates how to setup a combo in a cell to be bound to the value in the underlying business object. It shows friendly country names for their relevant lookup ID values.
Some important notes :
1. It utilizes a regular combo but the same setup should work with a RadComboBox
2. It uses the CellTemplate rather than the CellEditTemplate. This is for a reason - when not in edit mode , we still need the name displayed , rather than the ID.
3. The selected value in the combo , directly affects the value of the underlying business object- you may test it by placing a breakpoint in the setter of the CountryID property and playing with the combo.
4. For simplicity I have applied this to a flat RadGridView, but the same can be used in a nested Gridview in a hierarchy scenario.
Regards,
Pavel Pavlov
the Telerik team
<telerik:GridViewDataColumn.CellTemplate> in my project, but <telerik:GridViewColumn.CellTemplate>
is working but when i rand the project the edit template <telerik:GridViewColumn.CellEditTemplate> is not firing....how can i get it.
I would need a bit more information about the scenario you want to accomplish and your particular settings of the column. Do you want to define a CellTemplate for a GridViewColumn or GridViewDataColumn ? What do you mean that the CellEditTemplate is not firing - that the cell does not enter in edit-mode ?
Any relevant information would help me to provide you with an appropriate solution and sample project if needed.
All the best,
Maya
the Telerik team
I need some help with the mentioned scenario. I would like to have a RadComboBox iniode a CellEditTemplate, sounds easy but here is the catch. In Celltemplate, I am binding a textblock's text property to a string value from the database. In Edit mode Instead of typing in, I would like for the user to pick from 3 predefined values so here is where I place my RadComboBox with 3 CmboBoxItems. In my case the radcombobox's Item source is not bound but it is rather a stand alone element that needs to pass the selected item's content back.
Is this the right way of doing this or should I do something else?
Hope the above makes sense.
Regards
SD
In order to suggest any further, I would need a bit more details. What will be the relation between the statically define combo box items and the value to be displayed in view mode ? What is the type of the property bound to this column ? Is using GridViewComboBoxColumn not appropriate ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I guess I can use GridViewComboBoxColumn , however how can I add extra values to the bound values. Reason I am asking this is because in my scenario I have 3 selections - Missing, On File and Not Needed. The database is already been set up to have all cells default to "Missing" so when i bind I would like to present the user with a drop down and he/she can select any of the 3 options and update that row. So in my initial binding the GridViewComboBoxColumn will only show "Missing" than how do I manually add the additional options to the bound value?
Thanks
SD
You can define all three values in the source of the GridViewComboBoxColumn and set the property of each item connecting the two sources so that it points to the default value. I am sending you a sample project illustrating this idea. Will that work for you ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
In your project the GridViewComboBox column is bound instead of static values added to it's source. I am sorry but for some reason I can not understand and I am not very good with MVVM. All I am trying to do is have the column bound to the database but add the 3 choices manually in xaml. Does that make sense?
You can define a static items in the combo box, but you will need then to handle all the logic for Bindings and update of the corresponding properties on your own. That is why I would recommend you to work with a GridViewComboBoxColumn directly.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Could you help me with the same project but with the use of a RIA services instead of MVVM. I am having a really hard time trying to figure this out. I would like to use the GridViewComboBoxColumn and I even setup a separate table to hold the values that I want when in edit mode but can not figure out how to bound the GridViewComboBoxColumn to the new entity set and pass the SelectedValueID back to the original table that the GridView column is bound to.
Hope this makes sense.
SD
Please take a look at this forum thread for a reference.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>