如何从组合框到其他文本框获取价值 [英] How Can I Get Value From Combo Box To Other Textbox
问题描述
string CS = ConfigurationManager.ConnectionStrings [ DBCS跨度>]的ConnectionString。
使用(SqlConnection con = new SqlConnection(CS))
{
SqlDataAdapter da = new SqlDataAdapter( 从中选择catName tblcatProducts,con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBoxFK_catid.DataSource = dt;
comboBoxFK_catid.DisplayMember = catName;
comboBoxFK_catid.ValueMember = catId;
}
如何从 ValueMember
获得价值使用(SqlConnection con = new SqlConnection(CS))
{
SqlDataAdapter da = new SqlDataAdapter(从tblcatProducts中选择catName,con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBoxFK_catid.DataSource = dt;
comboBoxFK_catid.DisplayMember =catName;
comboBoxFK_catid.ValueMember =catId;
< pre>
comboBoxFK_catid.SelectedValueChanged + = new EventHandler((object sender,EventArgs e)=>
{
var catId = comboBoxFK_catid.SelectedValue;
DataRow catDataRow = dt.Select(string .Format(catId = {0},catId))。First();
var itemArray = catDataRow.ItemArray;
});
}
首先你需要处理comboBoxFK_catid.SelectedValueChanged事件,每次都要注意其中comboBoxFK_catid来源的选定项目已更改。
然后检索所选项目的值,所以你
ll能够过滤您的DataTable以获取所选的DataRow。拥有有效的DataRow引用意味着一切:)!虽然DataRow的ItemArray属性将返回记录的数据!
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlDataAdapter da = new SqlDataAdapter("select catName from tblcatProducts", con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBoxFK_catid.DataSource = dt;
comboBoxFK_catid.DisplayMember = "catName";
comboBoxFK_catid.ValueMember = "catId";
}
How Can Get Value from "ValueMember
" to other Text box
using (SqlConnection con = new SqlConnection(CS)) { SqlDataAdapter da = new SqlDataAdapter("select catName from tblcatProducts", con); DataTable dt = new DataTable(); da.Fill(dt); comboBoxFK_catid.DataSource = dt; comboBoxFK_catid.DisplayMember = "catName"; comboBoxFK_catid.ValueMember = "catId"; <pre> comboBoxFK_catid.SelectedValueChanged += new EventHandler((object sender, EventArgs e) => { var catId = comboBoxFK_catid.SelectedValue; DataRow catDataRow = dt.Select(string.Format("catId = {0}", catId)).First(); var itemArray = catDataRow.ItemArray; }); }
first of all you need to handle comboBoxFK_catid.SelectedValueChanged event, to be aware of every time which the selected item at comboBoxFK_catid`s source is changed.
then after retrieving the selected items value, so you
ll be able to filter your DataTable to get the selected DataRow. having the valid DataRow reference means everything :) ! although ItemArray property of DataRow will return data of your record!
这篇关于如何从组合框到其他文本框获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!