Click here to Skip to main content
11,707,167 members (59,909 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WebForms
Hi want to display station code and staion name both in the listbox or combobox
private void getdatainsourcestation()
              con = new MySqlConnection();
              con.ConnectionString = ConfigurationSettings.AppSettings["constr"];
          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

Posted 6-Aug-12 22:09pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Refer this link[^]

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.
// 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.
// 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.

// 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.
// Display the index of the first selected item in the ListBox.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You may even get the data from the database as single column like below:
string str = "select scode + ' ' + sname as Details from stationcode;";
GuruOnu at 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)

  Print Answers RSS
0 OriginalGriff 141
1 Sergey Alexandrovich Kryukov 135
2 chainerlt 110
3 Maciej Los 80
4 ppolymorphe 79
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,512
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 7 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100