困难的 telerik:RadCombobox ItemsSource Binding

发布于 2024-12-02 06:33:48 字数 1393 浏览 0 评论 0原文

我遇到了一个困难的绑定情况。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-12-09 06:33:48

如果我理解正确,那么使用将可用选项列表与所选选项结合起来的多功能转换器怎么样?

在您的 ViewModel 中,保留可用选项的 ObservableCollection。这是您的数据项未使​​用的任何数字。每当数据项的 ToFrom 属性发生更改时,请更改可用选项列表。

然后将 ComboBox 绑定到可用选项列表,并使用多转换器将当前选定的项目添加到 ItemsSource

下面是一些粗略的伪代码。我没有通过编译器或任何东西运行它,但它应该给你一个总体思路。

视图模型

public ObservableCollection<int> AvailableNumbers;
public ObservableCollection<MyClass> DataObjects;

foreach(var obj in DataObjects)
{
    obj.PropertyChanged += DataObject_PropertyChanged;
}

void DataObject_PropertyChanged(src as object, e as PropertyChangedEventArgs)
{
    if (e.PropertyName == "To" || e.PropertyName == "From")
        // Adjust AvailableNumbers list
}

XAML

<ComboBox SelectedItem="{Binding From}">
    <ComboBox.ItemsSource>
        <MultiBinding Converter="{StaticResource CombineListAndObjectMultiConverter}">
            <Binding RelativeSource="{RelativeSource AncestorType={x:Type DataGrid}}" 
                     Path="DataContext.AvailableNumbers"/>
            <Binding Path="From" />
        </MultiBinding>
    </ComboBox.ItemsSource>
</ComboBox>

并且您的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 an ObservableCollection of available options. This is any number that is not being used by your data items. Whenever a data item's To or From 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

public ObservableCollection<int> AvailableNumbers;
public ObservableCollection<MyClass> DataObjects;

foreach(var obj in DataObjects)
{
    obj.PropertyChanged += DataObject_PropertyChanged;
}

void DataObject_PropertyChanged(src as object, e as PropertyChangedEventArgs)
{
    if (e.PropertyName == "To" || e.PropertyName == "From")
        // Adjust AvailableNumbers list
}

XAML

<ComboBox SelectedItem="{Binding From}">
    <ComboBox.ItemsSource>
        <MultiBinding Converter="{StaticResource CombineListAndObjectMultiConverter}">
            <Binding RelativeSource="{RelativeSource AncestorType={x:Type DataGrid}}" 
                     Path="DataContext.AvailableNumbers"/>
            <Binding Path="From" />
        </MultiBinding>
    </ComboBox.ItemsSource>
</ComboBox>

And your CombineListAndObjectMultiConverter would simply add an object to a list and return the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文