Home Forums WPF controls Xceed DataGrid for WPF ComboBox in DataGrid column

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26851 |

    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.

    Imported from legacy forums. Posted by Anders Daling (had 5943 views)

    Xceed Support
    Member
    Post count: 5658

    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?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 1358 views)

    User (Old forums)
    Member
    Post count: 23064

    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.

    Imported from legacy forums. Posted by Anders Daling (had 1152 views)

    Xceed Support
    Member
    Post count: 5658

    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}

    Imported from legacy forums. Posted by Jenny [Xceed] (had 5452 views)

    User (Old forums)
    Member
    Post count: 23064

    Jenny,

     Can you tell me how to create  xlmns:local ….so that I can referene local:MainWindow .

    I create a namespace in my vbnet codebehind and cant seem to reference it in the creation of ‘xlmns:local’ in my xaml.

     

    Any advice??

     

    Imported from legacy forums. Posted by kevin (had 2734 views)

    User (Old forums)
    Member
    Post count: 23064

    Even if local:MainWindow is replaced with another valid object like

    x

    :Type xcdg:Cell

     Error message: Mode must be specified for relative source

     

    is given

     

     

    Imported from legacy forums. Posted by kevin (had 4218 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.