By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

ListBox SelectedItem

P: 3
I got a problem with ListBox.SelectedItem

When I bound a listbox to a database, and try to convert listbox.selecteditem to string, it returns me "System.Data.DataRowView".

And later I try to use listbox.text, it works.

Does anyone know what's wrong?

Expand|Select|Wrap|Line Numbers
  1. private DataSet ListDataBinding()
  2.         {
  3.             SqlConnection cn = new SqlConnection();
  4.  
  5.             SqlDataAdapter da_returnDS;
  6.             DataSet returnDS_ds = new DataSet();
  7.  
  8.             string SQLStr = "";
  9.  
  10.             cn.ConnectionString = MMMP.MainDialogForm.connection_string;
  11.             cn.Open();
  12.  
  13.  
  14.             SQLStr = "Select distinct Date_Accept from Work_Order_History order by Date_Accept";
  15.  
  16.             da_returnDS = new SqlDataAdapter(SQLStr, cn);
  17.  
  18.             da_returnDS.Fill(returnDS_ds, "DistinctMember");
  19.             cn.Close();
  20.             return returnDS_ds;
  21.         }
  22.  
  23.         private void Sch_History_Frm_Load(object sender, EventArgs e)
  24.         {
  25.  
  26.             DataSet dS_Date = ListDataBinding();
  27.             lstb_Date.DataSource = dS_Date;
  28.             lstb_Date.DisplayMember = "DistinctMember.Date_Accept";
  29.  
  30.         }
  31.  
  32.         private void lstb_Date_SelectedIndexChanged(object sender, EventArgs e)
  33.         {
  34.             if (lstb_Date.SelectedIndex != -1)
  35.             {
  36.  
  37.  
  38.  
  39.              string hist_Date = Convert.ToString(lstb_Date.SelectedValue);
  40.  
  41.  
  42.             }
  43.         }
  44.  
Thank you
Oct 20 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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