如何在用户控制页面中检索选定的组合框项目 [英] How to retrieve selected Combo Box item in User Control Page

查看:73
本文介绍了如何在用户控制页面中检索选定的组合框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用户控制页面中检索选定的组合框项目

组合框控件在主窗口中。选择用户控件将加载选定的值

如何实现这个?

解决方案

在你的WindowDropDownMap类中写这个

  public   static   string  CMBSelectedValue { get ;  set ;} 



在SelectedIndexChanged事件分配值

 WindowDropDownMap.CMBSelectedValue =((ComboBoxItem)selectOption.SelectedItem).Content.ToString(); 



现在尝试在用户控件中获取值喜欢

  string  str = WindowDropDownMap.CMBSelectedValue; 


你可以试试这个。未经测试

 Window parentWindow = Window.GetWindow( this ); 
ComboBox cmb = parentWindow.Controls [ ComboBoxID] as ComboBox;



现在您可以获得价值

  string  val = cmb.Text; 



OR

 ComboBoxItem cmbItem = cmb.SelectedItem  as  ComboBoxItem; 
string val = cmbItem.Content.ToString();


 <   ComboBox     Horizo​​ntalAlignment   =    保证金  =  169,30,0,0    VerticalAlignment   = 顶部   宽度  =  201   名称  =  selectOption    SelectionChanged   =  ComboBox_SelectionChanged >  
< ComboBoxItem 内容 = 13.017063 / >
< ComboBoxItem 内容 = 13.017564 / >
< ComboBoxItem 内容 = 12.989084 / >
< ComboBoxItem < span class =code-attribute>内容 = 12.989313 / >
< / ComboBox >



下拉代码


How to retrieve selected Combo Box item in User Control Page
Combo Box Control is in Main Window.Upon Selection User Control will be loaded with selected values
how to achieve this?

解决方案

Write this in your WindowDropDownMap class

public static string CMBSelectedValue {get;set;}


On SelectedIndexChanged event assign value

WindowDropDownMap.CMBSelectedValue = ((ComboBoxItem)selectOption.SelectedItem).Content.ToString();


Now trying to get value in User Control like

string str = WindowDropDownMap.CMBSelectedValue;


You can try this. Not tested

Window parentWindow = Window.GetWindow(this);
ComboBox cmb = parentWindow.Controls["ComboBoxID"] as ComboBox;


Now You can get the value

string val = cmb.Text;


OR

ComboBoxItem cmbItem= cmb.SelectedItem as ComboBoxItem;
string val = cmbItem.Content.ToString();


<ComboBox HorizontalAlignment="Left" Margin="169,30,0,0" VerticalAlignment="Top" Width="201" Name="selectOption" SelectionChanged="ComboBox_SelectionChanged">
         <ComboBoxItem Content="13.017063"/>
         <ComboBoxItem Content="13.017564"/>
         <ComboBoxItem Content="12.989084"/>
         <ComboBoxItem Content="12.989313"/>
     </ComboBox>


Drop Down Code


这篇关于如何在用户控制页面中检索选定的组合框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆