473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to get the multiple columns in listbox while selection of combobox

hai
if i select name in combo box then i have get name and phone number of that respected name in list box. pleas help me.
i used below code but no use

Expand|Select|Wrap|Line Numbers
  1.  private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.             comboBox2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  5.             var connectionString = ConfigurationManager.ConnectionStrings["newproject"].ConnectionString;
  6.             SqlConnection cn = new SqlConnection(connectionString);
  7.             cn.Open();
  8.             try
  9.             {
  10.                 SqlCommand cmd = new SqlCommand("select contact_name +'              '+CAST(number as varchar(50)) as one from contact where contact_name=('" + comboBox2.Text + "')", cn);
  11.                 SqlDataReader dbr;
  12.  
  13.                 dbr = cmd.ExecuteReader();
  14.                // checkedListBox1.Items.Clear();
  15.                 //listBox2.Items.Clear();
  16.                 while (dbr.Read())
  17.                 {
  18.                     //string eid = (string)dbr["eid"];
  19.                     string name = (string)dbr["one"];
  20.                     listBox2.Items.Add(name);
  21.  
  22.                 }
  23.                 // checkedListBox1.Items.Remove(checkedListBox1.SelectedItem );
  24.             }
  25.             catch (Exception e1)
  26.             {
  27.                 MessageBox.Show(e1.Message);
  28.             }}
  29.  public void combo1sel()
  30.         {
  31.             SqlCommand com;
  32.             SqlDataAdapter sda;
  33.             DataSet ds;
  34.             string str;
  35.             var connectionString = ConfigurationManager.ConnectionStrings["newproject"].ConnectionString;
  36.             SqlConnection cn = new SqlConnection(connectionString);
  37.  
  38.             str = "select contact_name +'              '+CAST(number as varchar(50)) as one from contact";
  39.  
  40.             com = new SqlCommand(str, cn);
  41.             sda = new SqlDataAdapter(com);
  42.             ds = new DataSet();
  43.             sda.Fill(ds, "contact");
  44.             comboBox2.DataSource = ds.Tables["contact"];
  45.             comboBox2.DisplayMember = "one";
  46.             comboBox2.Text = "select";
  47.             comboBox2.Text = "";
  48.         }
Attached Images
File Type: jpg a1.jpg (63.6 KB, 137 views)
Sep 25 '14 #1
0 1156

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Beacher | last post by:
Morning all, I have a listbox, and I want to populate it with a table.. right now the listbox's rowsource is set to SELECT * FROM tblCondition but it only grabs the first field from the table and...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
1
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in...
2
by: Rosanne | last post by:
Hi All - I have a strange problem - I have an aspx page that contains server-side, multi-select listbox. The AutoPostBack property is set t false. The user should click on an item in the...
4
by: Brandon Potter | last post by:
I think I'm going crazy, but I cannot remember how to create a listbox with multiple columns as well as the sortable header block (a la Outlook message list). I've seen the examples of how to...
2
by: scratchadere | last post by:
I am tryin to partition a listbox into multiple columns.Here is the real problem.I am getting data from MS ACCESS database.I want to display it juz like how an email account displays unread messages...
5
by: Randy | last post by:
Hi, I'm have a form with a listbox and a few textboxes on it. Based on the user's selection in the listbox, I want the bindingsource to update the textboxes with the corresponding values. I have...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
0
by: Germaris | last post by:
Hi there! Is it possible to make multiple selections in a ComboBox ? i.e. make n consecutive selections and store them in an array or make n selections in the open list of the CB by using (for...
3
by: John | last post by:
Hi Does listbox in vs2008 support multiple columns? I have not been able to set the column widths property to 10, 20, 30 for instance as it expects an int32 value. Thanks Regards
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.