简体   繁体   中英

Databinding within Cell templated Devexpress:GridControl not working

I try to bind a List property SubscribedSymbols within a class object StrategySubscription as part of List to comboboxes in each cells of a specific column in a Devexpress GridControl but cannot get the data binding to work.

The auto column generator works and populates values onto the grid. So, I am sure the data exists.

I attached the xaml code and data object as well as a screenshot of the current output.

Can you please help to get the data binding to work correctly? I want the collection of strings within SubscribedSymbols to be populated in the comboboxes of each cell in the templated column.

PS: The first 3 grid columns and associate cells bind perfectly fine, the only problem lies with getting the data bound to the combobox in each cell of the last column.

public class StrategySubscription
    {
        public Guid StrategyId { get; set; }
        public string StrategyName { get; set; }
        public int CapitalAllocation { get; set; }
        public List<string> SubscribedSymbols { get; set; }

        public StrategySubscription(string strategyName, Guid strategyId, int capitalAllocation, List<SymbolSubscription> symbolSubscriptions)
        {
            StrategyName = strategyName;
            StrategyId = strategyId;
            CapitalAllocation = capitalAllocation;
            SubscribedSymbols = symbolSubscriptions.Select(x => x.Symbol.SymbolId).ToList();
            //SubscribedSymbols = String.Join(", ", symbolSubscriptions.Select(x => x.Symbol.SymbolId).OrderBy(x=>x));
        }
    }




<dxg:GridControl x:Name="StrategyGrid"  ItemsSource="{Binding StrategySubscriptions}" AutoGenerateColumns="None">
                    <dxg:GridControl.Columns>
                        <dxg:GridColumn Header="Strategy Id" Binding="{Binding StrategyId}"/>
                        <dxg:GridColumn Header="Strategy Name" Binding="{Binding StrategyName}"/>
                        <dxg:GridColumn Header="Strategy Capitalization" Binding="{Binding CapitalAllocation}"/>
                        <dxg:GridColumn Header="Symbol Subscription">
                            <dxg:GridColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox ItemsSource="{Binding SubscribedSymbols}"/>
                                </DataTemplate>
                            </dxg:GridColumn.CellTemplate>
                        </dxg:GridColumn>
                    </dxg:GridControl.Columns>

                    <dxg:GridControl.View>
                        <dxg:TableView AllowEditing="False" AutoWidth="True" BestFitArea="All" AllowBestFit="True" ShowGroupPanel="True" ShowSearchPanelMode="Always" NavigationStyle="Row"/>
                    </dxg:GridControl.View>
                </dxg:GridControl>

Add Data to your binding:

...
<dxg:GridColumn Header="Symbol Subscription">
    <dxg:GridColumn.CellTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding Data.SubscribedSymbols}"/>
        </DataTemplate>
    </dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...

If you using DE controls the better option is using dxe:ComboBoxEdit instead of ComboBox .

...
<dxg:GridColumn Header="Symbol Subscription">
    <dxg:GridColumn.CellTemplate>
        <DataTemplate>
            <dxe:ComboBoxEdit  
                ItemsSource="{Binding Data.SubscribedSymbols}"/>
        </DataTemplate>
    </dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM