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

set combobox selected value at runtime in a gridview

2 Answers 719 Views
GridView
This is a migrated thread and some comments may be shown as answers.
maria
Top achievements
Rank 1
maria asked on 22 Oct 2018, 05:33 AM

Hi,

I have a grid with 4 columns. On selecting/changing value for 3rd column(i.e.: NewFamily) I want to programmatically set some value for the combobox in 4th column (selected value as well as list)

Here is the xaml:
        <telerik:RadGridView Grid.Row="0"  x:Name="PartFamilyGrid" AutoGenerateColumns="False" 
                             ColumnWidth="*" MinHeight="150"
                             RowIndicatorVisibility="Collapsed" SelectionChanged="PartFamilyGrid_SelectionChanged"
                             >  
                <telerik1:StyleManager.Theme>
                    <telerik1:VisualStudio2013Theme/>
                </telerik1:StyleManager.Theme>
                <telerik:RadGridView.Columns>
                
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Family}"    IsReadOnly="True" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Part}"      IsReadOnly="True" />

                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox ItemsSource ="{Binding NewFamily}" SelectionChanged="NewFamilySelected" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.Header>New Family</telerik:GridViewDataColumn.Header>
                </telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox ItemsSource ="{Binding NewPart}" SelectionChanged="NewPartSelected" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.Header>New Part</telerik:GridViewDataColumn.Header>
                </telerik:GridViewDataColumn>
                
                
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

Items of this RadGridView are objects of this class
    public class PartFamilyGridItem : INotifyPropertyChanged
        {
        public string Family
            {
            get; set;
            }
        public string Part
            {
            get; set;
            }
        public List<string> NewFamily
            {
            get; set;
            }
        public List<string> NewPart
            {
            get; set;
            }

        public event PropertyChangedEventHandler PropertyChanged;
        }

In the SelectionChanged event (NewFamilySelected) for the RadComboBox in 3rd column i want to handle this task. But I am not sure how to do it.
Do I need to get the row of the RadComboBox (from 3rd col) for which value is modified, select the RadComboBox from 4th col and finally change the selectedValue?

 

A similar issue is handled here https://www.telerik.com/forums/change-the-cell-content-at-runtime#MtiwER8x9USdCWTtLyu5_A

but I am not getting how to handle it for combobox

2 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 24 Oct 2018, 01:19 PM
Hello Maria,

Thank you for the provided code.

My understanding is that you want to populate the ItemsSource of the ComboBox inside the 4th column when the selection in the 3rd column is changed. The demonstrated approach in the CascadingComboboxColumns SDK example, suggested in the referenced forum thread, looks similar to what you are going for. There might only be differences in terms of the structure of the data on your end.

By looking at the provided xaml, it seems that you want to populate the RadComboBox which ItemsSource is bound to the "NewPart" property. If that is the case, then in the SelectionChanged event of the other RadComboBox(the one bound to the "NewFamily" property), you will have to populate the "NewPart" property. Please, give this approach a try and let me know how it goes. 

On a side note, you can check out the ComboBox Column article in our documentation, if you have not done so already.

Hope this helps.

Regards,
Vladimir Stoyanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
maria
Top achievements
Rank 1
answered on 25 Oct 2018, 07:22 AM

Hi Dilyan,

Thank you.

The sample answers my question

Tags
GridView
Asked by
maria
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
maria
Top achievements
Rank 1
Share this question
or