繁体   English   中英

wpf c#静态组合框选择需要更新进行数据库调用的第二个组合框

[英]wpf c# static combobox selection needs to update second combobox that makes a DB call

我是使用DevExpress MVVM的WPF的新手,我有一个静态组合框,当用户选择一天时,我想通过传递一个int日并进行数据库调用来更新第二个组合框,以使用基于路由的路由来刷新该组合框那天。 这是我所拥有的:

->

    <Label Content="Route:" Grid.Column="2" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="9,60,0,0" Name="lblRoute" VerticalAlignment="Top" />
    <ComboBox Grid.Column="2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="127,65,0,0" Name="cboRoute" VerticalAlignment="Top" Width="120" 
                DataContext="{Binding}" ItemsSource="{Binding Path=RouteList}"  DisplayMemberPath="{Binding RouteName}" SelectedValue="{Binding RouteID}" Grid.ColumnSpan="2" 
              IsSynchronizedWithCurrentItem="true"/>

ViewModel:

 public ObservableCollection<RouteTest> BindRouteComboBox2(int day)
     {
          mgr = new SRMSRailManagerBLL();
        mgr.OpenConnection(ConfigurationManager.ConnectionStrings["SRMSSqlProvider"].ConnectionString);
        //might not want to pass dataset
        _routeDS = mgr.getRoutesForCombo(day);
        _routeDV = _routeDS.Tables[0].DefaultView;
        //cboRoute.ItemsSource = ds.Tables[0].DefaultView;
        //cboRoute.DisplayMemberPath = ds.Tables[0].Columns["RouteName"].ToString();
        //cboRoute.SelectedValuePath = ds.Tables[0].Columns["RouteID"].ToString();
        _routeList = new ObservableCollection<RouteTest>();
        foreach (DataRow row in _routeDV.Table.Rows)
        {
            RouteTest r = new RouteTest(Convert.ToInt32(row.ItemArray[0]), row.ItemArray[1].ToString());
            _routeList.Add(r);

        }


        mgr.CloseConnection();
         return _routeList;

当我单击第一个组合框时,我在_SelectionChanged()中填充了“星期一”,我想要的是Tag值“ 1”,这样我就可以传递给BindRouteComboBox(day)过程来更新第二个组合框仅显示第1天的路线,而不显示我的数据库表中的每条路线。 这应该很简单,我必须在这里错过一些简单的东西。

谢谢,

嗨,请使用SelectedValue而不是SelectedValuePath

string temp = (sender as ComboBox).SelectedValue.ToString();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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