This project has moved. For the latest updates, please go here.

CheckComboBox

Jul 30, 2014 at 1:38 PM
Edited Jul 30, 2014 at 1:42 PM
Hello. My code worked well, but at some point of re-factoring, upgrade Xceed libraries, etc it stopped to work.

I compared all parts of my code with an old one, and everything seems to be the same, except upgraded Xceed libraries to the latest version.

Displaying is working perfectly, but as soon as I expand CheckComboBox, it displays me Id fields instead of DisplayMemberPath field.

If I change CheckComboBox to ComboBox everything works perfectly.

No Binding or other errors in Output window...

Here is my CellEditorTemplate:

   <xcdg:CellEditor x:Key="DataGridCheckComboBoxCellEditor">

        <xcdg:CellEditor.EditTemplate>

            <DataTemplate>

                <xctk:CheckComboBox

                                                        HorizontalAlignment="Stretch"

                                                        VerticalAlignment="Center"

                                                        DisplayMemberPath="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.DisplayMemberPath,Mode=OneWay}"

                                                        ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.ItemsSource, Mode=OneWay}"

                                                        SelectedValue="{xcdg:CellEditorBinding}"

                                                        ValueMemberPath="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.ValuePath}"/>

            </DataTemplate>

        </xcdg:CellEditor.EditTemplate>

    </xcdg:CellEditor>
Here is usage of it, inside Grid:
   <xcdg:Column Title="Routes"

                                     FieldName="ConflictedRoutes"

                                     CellEditor="{StaticResource DataGridCheckComboBoxCellEditor}" AllowGroup="False"

                                     AllowSort="False" CellEditorDisplayConditions="Always">

                            <xcdg:Column.ForeignKeyConfiguration>

                                <xcdg:ForeignKeyConfiguration

                                    ItemsSource="{Binding Source={StaticResource RouteCollectionViewSource}}"

                                    DisplayMemberPath="Name" ValuePath="Index" />

                            </xcdg:Column.ForeignKeyConfiguration>

                        </xcdg:Column> 
Developer
Aug 5, 2014 at 8:33 PM
Hi, Based on your sample, it worked for me. I can see the name of the routes in the CheckComboBox.
Here's my sample :
<Window x:Class="WpfApplication82.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
        xmlns:local="clr-namespace:WpfApplication82"
        Title="MainWindow" Height="350" Width="525">
   <Window.Resources>
      <local:Routes x:Key="Routes" />
      <CollectionViewSource x:Key="RouteCollectionViewSource"
                            Source="{Binding Source={StaticResource Routes}, Path=RouteList}" />
      
      <xcdg:CellEditor x:Key="DataGridCheckComboBoxCellEditor">
         <xcdg:CellEditor.EditTemplate>
            <DataTemplate>
               <xctk:CheckComboBox HorizontalAlignment="Stretch"
                                   VerticalAlignment="Center"
                                   DisplayMemberPath="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.DisplayMemberPath,Mode=OneWay}"
                                   ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.ItemsSource, Mode=OneWay}"
                                   SelectedValue="{xcdg:CellEditorBinding}"
                                   ValueMemberPath="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:Cell.CellEditorContext).ForeignKeyConfiguration.ValuePath}" />
            </DataTemplate>
         </xcdg:CellEditor.EditTemplate>
      </xcdg:CellEditor>
   </Window.Resources>
   <Grid>
      <xcdg:DataGridControl x:Name="_dataGrid">
         <xcdg:DataGridControl.Columns>
            <xcdg:Column Title="Routes"
                         FieldName="ConflictedRoutes"
                         CellEditor="{StaticResource DataGridCheckComboBoxCellEditor}"
                         AllowGroup="False"
                         AllowSort="False"
                         CellEditorDisplayConditions="Always">
               <xcdg:Column.ForeignKeyConfiguration>
                  <xcdg:ForeignKeyConfiguration ItemsSource="{Binding Source={StaticResource RouteCollectionViewSource}}"
                                                DisplayMemberPath="Name"
                                                ValuePath="Index" />
               </xcdg:Column.ForeignKeyConfiguration>

            </xcdg:Column>
         </xcdg:DataGridControl.Columns>
      </xcdg:DataGridControl>
   </Grid>
</Window>

namespace WpfApplication82
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();

      _dataGrid.ItemsSource = new List<MyData>()
      {
        new MyData(),
        new MyData()
      };
    } 
  }

  public class MyData
  {
    public object ConflictedRoutes
    {
      get;
      set;
    }
  }

  public class Route
  {
    public string Name
    {
      get;
      set;
    }

    public int Index
    {
      get;
      set;
    }

    public Route()
    {
    }
  }

  public class Routes
  {
    ObservableCollection<Route> _routeList = new ObservableCollection<Route>();

    public ObservableCollection<Route> RouteList
    {
      get
      {
        return _routeList;
      }
    }

    public Routes()
    {
      _routeList.Add( new Route() { Index = 0, Name = "First Route" } );
      _routeList.Add( new Route() { Index = 1, Name = "Second Route" } );
      _routeList.Add( new Route() { Index = 2, Name = "Third Route" } );
      _routeList.Add( new Route() { Index = 3, Name = "Fourth Route" } );
    }
  }
}
Aug 6, 2014 at 12:56 AM
Yes. The provided example works perfectly.
However, based on some condition, I still can't figure out what's exactly works wrong.
But during expanding ComboBox it raises ToString() method for each Route inside RouteList collection.
Since, ToString() returns me Id (GUID), I see GUID value, instead of Name.
If instead of returning Id I'll return Name in ToString() method, everything will work perfectly, but, that's not a solution of the issue.