Welcome to the Xceed Community Sign in | Join | Help
Community Search  

ComboBox in DataGrid column

Sort Posts: Previous Next
  •  04-21-2008, 8:11 AM Post no. 11626

    ComboBox in DataGrid column

    Hi,
    I'm having trouble displaying a combox as a cell content in the datagrid.
    I'm using a DataSet as the DataContext. I currently have two tables:
    1. The data for the grid (named ItemList with the columns Name and UnitId)
    2. The the data for the combobox (named Units with the columns Id and Description)
    The column UnitId in table ItemList references (one-to-many) the column Id in Units.

    The XAML looks like this:
    <xcdg:DataGridControl ItemsSource="{Binding Path=ItemList}" AutoCreateColumns="False">
    <xcdg:DataGridControl.Columns>
    <xcdg:Column Title="Name" FieldName="Name" />
    <xcdg:Column FieldName="UnitId" Title="Unit">
    <xcdg:Column.CellEditor>
    <xcdg:CellEditor>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <ComboBox ItemsSource="{Binding Path=Units}"
    SelectedValuePath="Id"
    DisplayMemberPath="Description"
    SelectedValue="{xcdg:CellEditorBinding}" />
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>
    </xcdg:Column.CellEditor>
    </xcdg:Column>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    The problem is that the combobox is empty when I try to edit the cells content.
  •  04-21-2008, 9:16 AM Post no. 11629 in reply to 11626

    Re: ComboBox in DataGrid column

    Do you have any binding errors in the output window? If you use the same bindings on the combobox outside the grid, are the values displayed?


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  04-21-2008, 10:02 AM Post no. 11632 in reply to 11629

    Re: ComboBox in DataGrid column

    Hi,
    Thanks for your quick response.
    Yes, as a matter of fact, I get a an error message:
    "System.Windows.Data Error: 35 : BindingExpression path error: 'Units' property not found on 'object' ''String' (HashCode=-1551042432)'. BindingExpression:Path=Units; DataItem='String' (HashCode=-1551042432); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')"
    When I use the same bindings on a combobox outside the grid, values are displayed correctly.
  •  04-21-2008, 11:52 AM Post no. 11636 in reply to 11632

    Re: ComboBox in DataGrid column

    The editor's DataContext is the content of the cell that it is editing; therefore, what the binding error indicates is that the Units property does not exist on the string value (the cell's content).

    That said, try using a RelativeSource binding with the AncestorType set to the class which exposes the Units property.

    {Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=Units}


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under:
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.