困难的 telerik:RadCombobox ItemsSource Binding
我遇到了一个困难的绑定情况。我正在使用 Telerik RadGridView 和 GridViewComboBoxColumn。我有两个组合框,一个“From”和一个“To”,绑定到单独的 List
。当用户放下“从”组合框打开时,显示的值应反映“可用”整数范围。可用整数由当前行 From 和 To 范围中的整数范围减去其他行中的范围组成。
我遇到的问题是“From”组合框是一个绑定的List
,当我创建可用整数列表时,它会删除在所有其他未选定行中找到的整数范围。例如,如果我有一个 List
1-48,第一行的范围为 25-36,第二行的范围为 37-42。当用户将第一行的“发件人”组合框打开时,他们会看到列表 1-36 和 43-48。范围 37-42 不可用,因为它正在第二行上使用。
第 1 行 从 = 25 到 = 36 第 2 行 从 = 37 到 = 42
这就是问题: 由于绑定列表不包含整数 37-42,因此第二行的选定项目不再在列表中可用,并且不会显示在网格中。 第 1 行的“来自”组合框关闭后,第二行的“来自”组合框应显示“37”。我需要一种方法来记住未选定行的值,并在“来自”组合框中显示这些值,即使它们未在绑定列表中找到。
仅供参考:我不关心这里的 TO 组合框,很可能 FROM 的任何解决方案也可以应用于 TO 组合框。
我知道这很令人困惑,如果您有疑问,请询问。基本上,当这些项目不再出现在绑定列表中时,我需要一种方法来保留非选定行选定的项目。我只需要显示原始选择的值。在打开下拉列表之前,第二行组合框中的项目并不重要。然后这种情况就会逆转,我需要能够回忆起第一行的所选项目。
telerik:GridViewComboBoxColumn x:Name="cboFrom2" Header="From" Width="Auto"
IsFilterable="False" IsGroupable="False" IsReorderable="False" IsSortable="False"
DataMemberBinding="{Binding StrandFrom}" EditTriggers="CellClick" >
<telerik:GridViewComboBoxColumn.EditorStyle>
<Style TargetType="telerik:RadComboBox">
<Setter Property="OpenDropDownOnFocus" Value="True"/>
</Style>
</telerik:GridViewComboBoxColumn.EditorStyle>
</telerik:GridViewComboBoxColumn>
I'm running into a difficult binding situation. I'm using Telerik RadGridView with GridViewComboBoxColumn. I've got two combo boxes a "From" and a "To" bound to separate List<int>
. When the user drops the From combo box open the values presented should reflect an "available" range of integers. The available integers consists of the range of integers in the current rows From and To range minus the ranges in the other rows.
The problem I'm having is that the From combo box is a bound List<int>
and when I create the available integers list it removes the range of integers found in all the other non-selected rows. For example if I have a List<int>
1-48 and the first row has a range of 25-36 and the second row has a range of 37-42. When the user drops the From combo box open on the first row they are presented with a list 1-36 and 43-48. The range 37-42 is not available because it's in use on the second row.
Row 1
From = 25 To = 36
Row 2
From = 37 To = 42
THIS IS THE PROBLEM:
Because the bound list doesn't contain the integers 37-42 what happens is the selected item for the second row is no longer available in the list and won't display in the grid.
Row two's From combo box should display '37' after Row 1's From combo box closes. I need a way to remember the values of non selected rows and display those values in the From combo box even though they aren't found in the bound list.
FYI: I'm not concerned about the TO combo box here, it's likely any solution for FROM can also be applied to the TO combo box.
I know this is confusing please ask if you have questions. Basically I need a way to retain the non-selected rows selected items when those items are no longer present in the bound list. I only need to display the original selected value. The items in the combo box for the second row are of no importance until it's drop down is opened. Then this situation reverses and I would need to be able to recall the selected item for the first row.
telerik:GridViewComboBoxColumn x:Name="cboFrom2" Header="From" Width="Auto"
IsFilterable="False" IsGroupable="False" IsReorderable="False" IsSortable="False"
DataMemberBinding="{Binding StrandFrom}" EditTriggers="CellClick" >
<telerik:GridViewComboBoxColumn.EditorStyle>
<Style TargetType="telerik:RadComboBox">
<Setter Property="OpenDropDownOnFocus" Value="True"/>
</Style>
</telerik:GridViewComboBoxColumn.EditorStyle>
</telerik:GridViewComboBoxColumn>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,那么使用将可用选项列表与所选选项结合起来的多功能转换器怎么样?
在您的
ViewModel
中,保留可用选项的ObservableCollection
。这是您的数据项未使用的任何数字。每当数据项的To
或From
属性发生更改时,请更改可用选项列表。然后将 ComboBox 绑定到可用选项列表,并使用多转换器将当前选定的项目添加到 ItemsSource
下面是一些粗略的伪代码。我没有通过编译器或任何东西运行它,但它应该给你一个总体思路。
视图模型
XAML
并且您的
CombineListAndObjectMultiConverter
只需将一个对象添加到列表中并返回该列表。If I understand you correctly, what about making use of a multi converter that combines the list of available options with the selected option?
In your
ViewModel
, keep anObservableCollection
of available options. This is any number that is not being used by your data items. Whenever a data item'sTo
orFrom
property changes, alter the list of Available options.Then bind your ComboBoxes to that list of available options, and use a multi converter to add the currently selected item to the ItemsSource
Here's some rough pseudo-code. I didn't run it through a compiler or anything, but it should give you the general idea.
View Model
XAML
And your
CombineListAndObjectMultiConverter
would simply add an object to a list and return the list.