选中comboBox 一行以后获取选中的value
绑定数据代码如下:DataTabledt=newDataTable();dt.Columns.Add("BuildName");dt.Columns.Add("Build...
绑定数据代码如下:
DataTable dt=new DataTable();
dt.Columns.Add("BuildName");
dt.Columns.Add("BuildID");
dr["BuildName"]=build.Name;
dr["BuildID"] = build.Id;
dt.Rows.Add(dr);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "BuildName";
comboBox1.ValueMember = "BuildName";
我选中一行后怎样获得当前行的Value而不是text?
这个事件代码该怎样写?
private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
{
}
上面一段代码更正如下:
comboBox1.DisplayMember = "BuildName";
comboBox1.ValueMember = "BuildID"; 展开
DataTable dt=new DataTable();
dt.Columns.Add("BuildName");
dt.Columns.Add("BuildID");
dr["BuildName"]=build.Name;
dr["BuildID"] = build.Id;
dt.Rows.Add(dr);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "BuildName";
comboBox1.ValueMember = "BuildName";
我选中一行后怎样获得当前行的Value而不是text?
这个事件代码该怎样写?
private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
{
}
上面一段代码更正如下:
comboBox1.DisplayMember = "BuildName";
comboBox1.ValueMember = "BuildID"; 展开
展开全部
private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
{
string strText =string.Empty;
string strValue =string.Empty;
strText = ((DataRowView)comboBox1.SelectedItem)["BuildName"].ToString(); //取得Text
strValue = ((DataRowView)comboBox1.SelectedItem)["BuildID"].ToString(); //取得Value
strValue = comboBox1.SelectedValue.ToString(); //取得Value,也可以
}
{
string strText =string.Empty;
string strValue =string.Empty;
strText = ((DataRowView)comboBox1.SelectedItem)["BuildName"].ToString(); //取得Text
strValue = ((DataRowView)comboBox1.SelectedItem)["BuildID"].ToString(); //取得Value
strValue = comboBox1.SelectedValue.ToString(); //取得Value,也可以
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询