最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

combobox - Telerik RadGridView for WPF ComboBoxColumn does not show right - Stack Overflow

programmeradmin3浏览0评论

I'm using Telerik RadGridView for WPF and trying to get one column to be a combobox column. I can do that, but you have to click into it to edit the cell, then click again to drop down to get it. I've tried the built in `GridViewComboBoxColumn' like this

            <telerik:GridViewComboBoxColumn
                DataMemberBinding="{Binding NewView}" 
                DisplayMemberPath="Reference"
                SelectedValueMemberPath="{Binding NewView}"
                ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ui:Dlg_SetLinks, AncestorLevel=1}, Path=DataContext.ViewsView}" 
                Header="New View"
                Width="*">
                <telerik:GridViewComboBoxColumn.ItemTemplate>
                    <DataTemplate DataType="{x:Type dataModel:ViewData}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Reference}" />
                            <TextBlock Text="(" Margin="10,0,0,0" Foreground="Gray" />
                            <TextBlock Text="{Binding DocumentName}" Foreground="Gray" />
                            <TextBlock Text=")" Foreground="Gray" />
                        </StackPanel>
                    </DataTemplate>
                </telerik:GridViewComboBoxColumn.ItemTemplate>
            </telerik:GridViewComboBoxColumn>

This shows the right objects and allows proper selection, but when you open the UI it only shows the text, not the combo box border and drop arrow, which doesn't show the user that the view can be changed. I have to click once on the cell to show the border and arrow and then again to open it before I can select something, which isn't great.

To fix this, I also tried just making it a data column and setting it to a combo box in the cell template like this:

             <telerik:GridViewDataColumn
                Header="New View"
                DataMemberBinding="{Binding NewView}"
                Width="*">
                <telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate DataType="{x:Type viewModel:LinkSetVM}">
                        <telerik:RadComboBox 
                            SelectedItem="{Binding NewView}"
                            ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ui:Dlg_SetLinks, AncestorLevel=1}, Path=DataContext.ViewsView}">
                            <telerik:RadComboBox.ItemTemplate>
                                <DataTemplate DataType="{x:Type dataModel:ViewData}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Reference}" />
                                        <TextBlock Text="(" Margin="10,0,0,0" Foreground="Gray" />
                                        <TextBlock Text="{Binding DocumentName}" Foreground="Gray" />
                                        <TextBlock Text=")" Foreground="Gray" />
                                    </StackPanel>
                                </DataTemplate>
                            </telerik:RadComboBox.ItemTemplate>
                        </telerik:RadComboBox>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellTemplate>
            </telerik:GridViewDataColumn>

This looks and clicks right, however for some reason it seems like each one is bound to the same underlying object. I have created sample data and have verified that each NewView property is a different object on the underlying VM. I also double verified this by replacing the RadComboBox with a simple TextBlock bound to the 'Reference' property of the object and it shows different for each row. However, the RadComboBox for each row shows exactly the same, and when I change one, it changes all the others.

How do I get this to work right? Is there a way to always show the dropdown on the first method and have the user just have to click once to get the dropdown? Or can the second one be bound properly to the object for the row?

发布评论

评论列表(0)

  1. 暂无评论