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

Combobox column

1 Answer 20 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 14 Dec 2011, 10:17 PM
I have a ViewModel that exposes a collection of items to be displayed in a grid.  It also exposes a list of options for one the the properties (grid columns)

I tried to use a Combobox column - setting the items source to the list of choices, and setting the DisplayMemberPath and SelectedValueMemberPath appropriately.

It works... kinda.  The problem is, the column doesn't show the selected values until you click on any cell in the column.  If you click on any cell, then all cells in the column show the correct text.  If you click on a cell in a different column, the values all disappear.  Even weirder - if you sort the column, it completely breaks, and the comboboxes don't even have items to select. (their items source becomes null)

Here is some simplified code.  What am I doing wrong?
<Grid x:Name="LayoutRoot" Background="White">
  <telerik:RadGridView AutoGenerateColumns="False" ItemsSource="{Binding Items}">
    <telerik:RadGridView.Columns>
      <telerik:GridViewComboBoxColumn
          SelectedValueMemberPath="ID"
          DisplayMemberPath="Name"
          ItemsSource="{Binding List}" DataMemberBinding="{Binding ListID}">
      </telerik:GridViewComboBoxColumn>
    </telerik:RadGridView.Columns>
  </telerik:RadGridView>
</Grid>

public class ViewModel
{
    public List<ListItem> List { get; private set; }
 
    public List<Item> Items { get; private set; }
 
    public ViewModel()
    {
        List = new List<ListItem>();
        List.Add(new ListItem() { ID = 1, Name = "Item 1" });
        List.Add(new ListItem() { ID = 2, Name = "Item 2" });
        List.Add(new ListItem() { ID = 3, Name = "Item 3" });
 
        Items = new List<Item>();
        Items.Add(new Item() { ListID = 1 });
        Items.Add(new Item() { ListID = 1 });
        Items.Add(new Item() { ListID = 2 });
    }
     
}
 
public class Item
{
    public int ListID { get; set; }
}
 
public class ListItem
{
    public int ID { get; set; }
    public string Name { get; set; }
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
  this.DataContext = new ViewModel();
}

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Dec 2011, 09:07 AM
Hello Justin Lee,

Please take a look at this article for a reference.
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or