将值从组合框传递到文本框 [英] passing values from combobox to textboxes
本文介绍了将值从组合框传递到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用桌面应用程序,我遇到的情况是将值成员和显示成员传递给组合框。现在,当我单击一个组合框时,我希望值成员显示在一个文本框上,显示成员显示在另一个文本框上。我怎样才能做到这一点?到目前为止,我的代码看起来像这些
Dim ds As 新 DataSet
Dim da 作为 新 SqlDataAdapter
Dim cmd < span class =code-keyword> As 新 SqlCommand
cmd.CommandText = [AP249_Falsifikati]。[ProcGetDostavuvaci]
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
cmd.Parameters.AddWithValue( @ TipDostavuvac,TipDostavuvac)
cmd.Parameters.AddWithValue( @ Datum,DatumPrimanje)
da.SelectCommand = cmd
da.Fill(ds, Tabela )
cmbDostavuvaci.Visible = True
cmbDostavuvaci.DataSource = ds.Tables( 0 )。DefaultView
cmbDostavuvaci.ValueMember = MatBR
cmbDostavuvaci.DisplayMember = Naziv
解决方案
正如我从您的代码中理解的那样,您可以通过这种方式填充组合框。
并且知道你想把所选的值放在文本框中。
在c#中它将是:String s = cmbDostavuvaci.SelectedItem.ToString();
你好,
因为你说你要展示点击组合框后,在文本框中显示值成员和显示成员。您可以使用 ComboBox.OnSelectedIndexChanged [^ ]完成此任务的方法。以下代码段显示了这一点。
private void cmbDostavuvaci_OnSelectedIndexChanged( Object sender,EventArgs e){
txtValue.Text = cmbDostavuvaci.SelectedValue.ToString();
txtDisplay.Text = cmbDostavuvaci.SelectedText;
}
http://stackoverflow.com/questions/16673551/value-member-in-textbox-and-display-member-in-组合框 [ ^ ]
I am working on a desktop application, and I have a situation where I pass a value member and a display member to a combobox. Now when I click a combobox I want the value member to show on one text box and the display member on the another text box. How can I do that? So far my code looks like these
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
cmd.CommandText = "[AP249_Falsifikati].[ProcGetDostavuvaci]"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
cmd.Parameters.AddWithValue("@TipDostavuvac", TipDostavuvac)
cmd.Parameters.AddWithValue("@Datum", DatumPrimanje)
da.SelectCommand = cmd
da.Fill(ds, "Tabela")
cmbDostavuvaci.Visible = True
cmbDostavuvaci.DataSource = ds.Tables(0).DefaultView
cmbDostavuvaci.ValueMember = "MatBR"
cmbDostavuvaci.DisplayMember = "Naziv"
解决方案
As i understand from your code, in this way you fill the combobox.
And know you want put the selected value in textbox.
in c# it will be:String s = cmbDostavuvaci.SelectedItem.ToString();
Hello,
Since you are saying that you want to show the value member and display member in the textboxes upon click of the combobox. You can use ComboBox.OnSelectedIndexChanged[^] Method to accomplish this. The following code snippet shows this.
private void cmbDostavuvaci_OnSelectedIndexChanged(Object sender, EventArgs e) { txtValue.Text = cmbDostavuvaci.SelectedValue.ToString(); txtDisplay.Text = cmbDostavuvaci.SelectedText; }
http://stackoverflow.com/questions/16673551/value-member-in-textbox-and-display-member-in-combobox[^]
这篇关于将值从组合框传递到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文