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

Binding combo box editor to property of row record

3 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 19 Dec 2008, 09:52 PM
Hello,

I am wondering if the following scenario is possible and how I would implement it.  Basically what I want to do is bind the list of items in a GridViewComboBoxEditor to a property of the data record for that row.

I have an object model that looks similar to this:

public class SomeObject
    public Field SelectedField { getset; }
    public string SelectedString { getset; }
 
public class Field
    public string[] ListOfAllowedItems; 

I have a grid that displays a list of SomeObject items, each of which contains a Field.  Depending on the Field the user selected, the list of items in another column needs to change according to a list defined on the Field object.

Any help would be greatly appreciated.

Thanks,
Joel

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosi
Telerik team
answered on 20 Dec 2008, 04:26 PM
Hello Joel,

I am not sure I get the scenario right.

A combo in the first column should let the user dynamically select the data displayed in the combobox editor in another column. Is that what you need ? If this is the task that you tried to achieve please find attached sample project.

It uses EventSetter for the ComboBox control to detect when the SelectedValue property is changed.Then the ItemSource of the second combobox is updated. You can download the project and review it.

If this is not the case, could you  please provide us with more information about the task you want to implement?

This information will help us to understand the task better and provide you with a sample.

Hope this helps.

Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
JP
Top achievements
Rank 1
answered on 22 Dec 2008, 04:29 PM
Hi Rosi,

Thanks for the sample project.  Your understanding of what I was looking for was correct.  I didn't use your code as it is though, but it did give me another idea and it helped me out a lot.  What I ended up doing was changing the ItemsSource for the dependent drop down using the GridViewCell.PreviewEditStart event instead.  I used this because then if the grid is pre-populated, the user doesn't have to select a value in the first column before the list in the 2nd column is updated.

In case others are interested here is the code I used:
xaml
<telerik:RadGridView Name="radGridView1" telerik:GridViewCell.PreviewEditStart="radGridView1_PreviewEditStart" /> 

C#
private void radGridView1_PreviewEditStart(object sender, Telerik.Windows.Controls.GridView.Cells.CellCancelRoutedEventArgs e) 
    GridViewCell cell = e.OriginalSource as GridViewCell; 
 
    if (cell != null && cell.DataColumn.UniqueName.Equals("Field2")) 
    { 
        SomeDataObject currentObject = radGridView1.CurrentItem as SomeDataObject; 
 
        ComboBoxEditorSettings editorSettings = (ComboBoxEditorSettings)((GridViewDataColumn)this.radGridView1.Columns["Field2"]).EditorSettings; 
        editorSettings.ItemsSource = currentObject.ChildObject.ListOfAllowedValuesForOtherField; 
 
        this.radGridView1.UpdateLayout(); 
    } 


Thanks for your help,

Joel
0
Hristo Deshev
Telerik team
answered on 23 Dec 2008, 09:28 AM
Hello Joel,

Great solution! It is a lot simpler than the original we thought out when discussing the problem with Rosi.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
JP
Top achievements
Rank 1
Answers by
Rosi
Telerik team
JP
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or