如何在列表框或组合框中显示多个字段 [英] how to display multiple fields in listbox or combobox

查看:77
本文介绍了如何在列表框或组合框中显示多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好希望在列表框或组合框中同时显示电台代码和站点名称

Hi want to display station code and staion name both in the listbox or combobox

private void getdatainsourcestation()
      {
          try
          {
              con = new MySqlConnection();
              con.ConnectionString = ConfigurationSettings.AppSettings["constr"];
              con.Open();
          }
          catch (Exception ex)
          {
              MessageBox.Show("Error"+ex.Message );
          }
          string str = "select scode,sname from stationcode;";
          da = new MySqlDataAdapter(str, con);
          ds = new DataSet();
          da.TableMappings.Add("table", "stationcode");
          da.Fill(ds, "stationcode");
          this.comboBox2.DataSource = this.ds;
          this.comboBox2.DisplayMember = "stationcode.sname ;
          this.comboBox2.ValueMember = "stationcode.sname";


      }



这是显示电台名称,但它也想要电台代码,请帮助

谢谢:



This is displaying station name but it also want station code please help

Thanks:

推荐答案

引用此链接

http://blog.dreamfactory.se/2011/01/20 /multiple-columns-in-asp-net-listbox/ [ }
//允许ListBox重新绘制并显示新项目.
listBox1.EndUpdate();

//从列表框中选择三个项目.
listBox1.SetSelected(1,true);
listBox1.SetSelected(3,true);
listBox1.SetSelected(5,true);

//将列表框中的第二个选定项显示到控制台.
System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems [1] .ToString());
//显示列表框中第一个选定项的索引.
System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices [0] .ToString());
}
Refer this link

http://blog.dreamfactory.se/2011/01/20/multiple-columns-in-asp-net-listbox/[^]

or try this

private void button1_Click(object sender, System.EventArgs e)
{
// Create an instance of the ListBox.
ListBox listBox1 = new ListBox();
// Set the size and location of the ListBox.
listBox1.Size = new System.Drawing.Size(200, 100);
listBox1.Location = new System.Drawing.Point(10,10);
// Add the ListBox to the form.
this.Controls.Add(listBox1);
// Set the ListBox to display items in multiple columns.
listBox1.MultiColumn = true;
// Set the selection mode to multiple and extended.
listBox1.SelectionMode = SelectionMode.MultiExtended;

// Shutdown the painting of the ListBox as items are added.
listBox1.BeginUpdate();
// Loop through and add 50 items to the ListBox.
for (int x = 1; x <= 50; x++)
{
listBox1.Items.Add("Item " + x.ToString());
}
// Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate();

// Select three items from the ListBox.
listBox1.SetSelected(1, true);
listBox1.SetSelected(3, true);
listBox1.SetSelected(5, true);

// Display the second selected item in the ListBox to the console.
System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString());
// Display the index of the first selected item in the ListBox.
System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());
}


您甚至可以从数据库中以单列的形式获取数据,如下所示:
You may even get the data from the database as single column like below:
string str = "select scode + ' ' + sname as Details from stationcode;";


这篇关于如何在列表框或组合框中显示多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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