Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
Posted

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());
}
 
Share this answer
 
v2
You may even get the data from the database as single column like below:
C#
string str = "select scode + ' ' + sname as Details from stationcode;";
 
Share this answer
 
Comments
Anurag Sarkar 7-Aug-12 8:22am    
i want multiple columns

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900