gpt4 book ai didi

c# - 选择 ComboBox 中的项目会影响不相关的 ComboBox

转载 作者:行者123 更新时间:2023-12-03 10:42:38 31 4
gpt4 key购买 nike

我有一个 XAML UserControl连接到 ImportPresenter View 模型。有四个ComboBox我的 XAML 中的项目:

  • CashActivityTypeBAI CashActivityTypesCombo , 哪些是必然的
    我的 CashActivityTypes数据查看
  • CashActivitiesBAI绑定(bind)到我的BAICashActivites数据查看
  • CashActivitiesCombo绑定(bind)到我的CashActivities数据 View 。

  • 我已经包含了我的 XAML 和三个类:
    PresenterImportPresenter是我的 View 模型。有一个静态的 Controller用作我的模型的类,它也连接到我的数据集。

    我的问题

    当一个项目被 CashActivityTypes 中的任何一个选择时ComboBox 项,它们各自的子数据 View 被过滤。然而,当 CashActivityTypeBAICashActivityTypesCombo已更改,它过滤两个子数据 View CashActivity组合框。

    我的 XAML
    <UserControl x:Class="Cash_Sheet_WPF.Views.Pages.CheckBAIPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Cash_Sheet_WPF.Views.Pages"
    xmlns:UserControls="clr-namespace:Cash_Sheet_WPF.Views.UserControls"
    xmlns:ViewModels="clr-namespace:Cash_Sheet_WPF.ViewModels"
    mc:Ignorable="d"
    d:DesignHeight="534" d:DesignWidth="1184">
    <Grid>
    <Grid.DataContext>
    <ViewModels:ImportPresenter/>
    </Grid.DataContext>
    <Grid.Background>
    <ImageBrush ImageSource="/Cash Sheet WPF;component/backgroundA.png" Stretch="UniformToFill"/>
    </Grid.Background>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="20"/>
    <RowDefinition Height="44"/>
    <RowDefinition Height="2*" MaxHeight="800"/>
    <RowDefinition Height="24"/>
    </Grid.RowDefinitions>
    <UserControls:MainMenu Grid.Row="0" VerticalAlignment="Top"/>
    <Grid Grid.Row="2" Margin="5,2,5,2" Width="Auto" Height="Auto" VerticalAlignment="Stretch">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*"/>
    <ColumnDefinition Width="2*"/>
    <ColumnDefinition Width="1*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="1*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Column="1">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*"/>
    <ColumnDefinition Width="1*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>
    <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Height="20" FontSize="9" Content="Cash Activity Type"/>
    <ComboBox x:Name="CashActivityTypeBAI" Grid.Column="1" Grid.Row="0" Height="20" FontSize="9" ItemsSource="{Binding CashActivityTypes, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="Type" SelectedValue="{Binding SelectedBAIType}" SelectedValuePath="Sequence"
    SelectedIndex="{Binding CashActivityTypeIndex, UpdateSourceTrigger=PropertyChanged}" Margin="0,2,0,0"/>
    <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" Height="20" FontSize="9" Content="Cash Activity"/>
    <Label Grid.Column="1" Grid.Row="1" Height="20" FontSize="9"
    Content="{Binding SelectedActivity, UpdateSourceTrigger=PropertyChanged}"/>
    <ComboBox x:Name="CashActivitiesBAI" Grid.Column="1" Grid.Row="1" Height="20" FontSize="9"
    ItemsSource="{Binding BAICashActivities, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="Activity"
    SelectedValue="{Binding SelectedBAIActivity}"
    SelectedValuePath="Sequence"
    SelectedIndex="{Binding CashActivityIndex, UpdateSourceTrigger=PropertyChanged}" Margin="0,2,0,0"/>
    </Grid>
    <Grid Grid.Column="2" Margin="2,0,0,0">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*"/>
    <ColumnDefinition Width="2*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="75"/>
    <RowDefinition Height="24"/>
    <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>
    <Label Grid.Column="0" Grid.Row="0" Content="Individual Transactions" FontSize="9"/>
    <Label Content="Cash Activity Type" FontSize="9" Grid.Row="1" Grid.Column="0" Margin="0,0,2,2" HorizontalAlignment="Right"/>
    <ComboBox x:Name="CashActivityTypesCombo" Grid.Row="1" Grid.Column="1" Width="Auto" Height="Auto" MaxHeight="20" MinHeight="20" Background="White"
    ItemsSource="{Binding CashActivityTypes, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="Type"
    SelectedValue="{Binding TypeSequence}"
    SelectedValuePath="Sequence"
    Margin="2,0,0,2" HorizontalAlignment="Stretch"/>
    <Label Content="Cash Activity" FontSize="9" Grid.Row="2" Grid.Column="0" Margin="0,2,2,2" HorizontalAlignment="Right"/>
    <ComboBox x:Name="CashActivitiesCombo" Grid.Row="2" Grid.Column="1" Width="Auto" Height="Auto" MaxHeight="20" MinHeight="20" Background="White"
    ItemsSource="{Binding CashActivities, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="Activity"
    SelectedValue="{Binding ActivitySequence}"
    SelectedValuePath="Sequence"
    Margin="2,2,0,2" HorizontalAlignment="Stretch"/>
    </Grid>
    </Grid>
    </Grid>
    </UserControl>
    ImportPresenterPresenter 的 child 类(class)
    namespace Cash_Sheet_WPF.ViewModels
    {
    /// <summary>
    /// Main Presenter Class - Parent class of other presenters
    /// </summary>
    public class Presenter : ObservableObject
    {

    #region Variables

    protected DataView _CashActivityTypes = Controller.FinanceDB.CashActivityType.DefaultView;
    protected DataView _CashActivities = Controller.FinanceDB.CashActivity.DefaultView;
    protected short _TypeSequence;
    protected short _ActivitySequence;

    #endregion


    #region Bindings

    //Returns a DataView from the CashActivityType table
    public DataView CashActivityTypes
    {
    get
    {
    return _CashActivityTypes;
    }
    set
    {
    _CashActivityTypes = value;
    RaisePropertyChangedEvent("CashActivityTypes");
    }
    }//END CASHACTIVITYTYPES

    public DataView CashActivities
    {
    get
    {
    return _CashActivities;
    }
    set
    {
    _CashActivities = value;
    RaisePropertyChangedEvent("CashActivities");
    }
    }//END CASHACTIVITIES

    public short TypeSequence
    {
    get
    {
    return _TypeSequence;
    }
    set
    {
    _TypeSequence = value;
    CashActivities.RowFilter = "Seq_CashActivityType = " + _TypeSequence;
    RaisePropertyChangedEvent("TypeSequence");
    }
    }//END TYPESEQUENCE

    #endregion

    }
    }
    ImportPresenter类,扩展了 Presenter类(class)
    namespace Cash_Sheet_WPF.ViewModels
    {
    public class ImportPresenter : Presenter
    {

    #region Variables

    //BAI Adjustment
    private DataView _BAI;
    private DataRowView _BAIRow;
    private DataView _BAICashActivities = Controller.FinanceDB.CashActivity.DefaultView;
    private short _SelectedBAIType = 0;
    private short _SelectedBAIActivity = 0;


    private long _CashActivityTypeIndex = 0;
    private long _CashActivityIndex = 0;
    private decimal _BucketAmount = 0;

    #endregion

    #region Bindings

    /// <summary>
    /// Cash Activities for the BAI Import Adjustment Section
    /// </summary>
    public DataView BAICashActivities
    {
    get
    {
    return _BAICashActivities;
    }
    set
    {
    _BAICashActivities = value;
    RaisePropertyChangedEvent("BAICashActivities");
    }
    }


    /// <summary>
    /// Gets the Selected Type index, to be used by the Combobox
    /// </summary>
    public long CashActivityTypeIndex
    {
    get
    {
    return _CashActivityTypeIndex;
    }
    set
    {
    _CashActivityTypeIndex = value;
    RaisePropertyChangedEvent("CashActivityTypeIndex");
    }
    }

    /// <summary>
    /// Stores the index of the currently selected Cash Activity
    /// </summary>
    public long CashActivityIndex
    {
    get
    {
    return _CashActivityIndex;
    }
    set
    {
    _CashActivityIndex = value;
    RaisePropertyChangedEvent("CashActivityIndex");
    }
    }

    /// <summary>
    /// Selected Cash Activity Type
    /// </summary>
    public short SelectedBAIType
    {
    get { return _SelectedBAIType; }
    set
    {
    _SelectedBAIType = value;
    RaisePropertyChangedEvent("SelectedBAIType");
    BAICashActivities.RowFilter = "Seq_CashActivityType = " + _SelectedBAIType;
    RaisePropertyChangedEvent("BAICashActivities");
    }
    }

    /// <summary>
    /// The Selected Cash Activity
    /// </summary>
    public short SelectedBAIActivity
    {
    get
    {
    return _SelectedBAIActivity;
    }
    set
    {
    _SelectedBAIActivity = value;
    RaisePropertyChangedEvent("SelectedBAIActivity");
    }
    }

    /// <summary>
    /// Returns the Index of text in a DataView
    /// </summary>
    /// <param name="dataView">DataView you are searching</param>
    /// <param name="stringItem">Search Text</param>
    /// <returns></returns>
    private long GetSelectedIndex(DataView dataView, string stringItem)
    {

    long selectedIndex = 0;
    foreach(DataRowView dataRowView in dataView)
    {
    if (dataRowView.Row.ItemArray.Contains(stringItem))
    {
    break;
    }
    else
    {
    selectedIndex++;
    }
    }

    return selectedIndex;

    }

    #endregion

    }
    }

    最佳答案

    所以我想我已经发现了发生了什么,如果有人有这个问题。

    当您创建两个不同的 DataView基于相同的对象DataTable对象,一个过滤器总是会影响另一个。

    所以不要从同一个 DataTable 创建一个新变量。 ,我用了GetData()数据表TableAdapter的功能结果很好。

    private DataView _MyView1 = TableAdapter1.GetData().DefaultView;
    private DataView _MyView2 = TableAdapter1.GetData().DefaultView;

    关于c# - 选择 ComboBox 中的项目会影响不相关的 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49682073/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com