473,396 Members | 1,996 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,396 software developers and data experts.

ListBox SelectedItem

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
0 1258

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

Similar topics

0
by: Jax | last post by:
I have a listbox. When the user selects an item i want to to take the text of the item and manipulate it. It wasn't working when autopostback was false, now it's true the event runs but i get an...
1
by: Jax | last post by:
I do this kind of thing all the time in applications but with ASP.NET i have problems with selecting an item in a list box and reading that selected text out when something like a button is...
2
by: David Ichilov | last post by:
I've class derived from "Object" class, with ToString() method overriden itc. , now i add object of this class to Windows.Forms.ListBox.Items collection, and it works fine, displaying what...
7
by: Ohad Asor | last post by:
Hello all, I have an ASP.NET page I've written using VS.NET2003, which have a ListBox in it. When I press a button in the form, I try to get the selected item in the list by calling...
3
by: Mark Lauser | last post by:
I have a Windows app (.net v1.1) and I am dragging from a list box. The first drag works fine, but all subsequent drags continue to pull the first item that was dragged. It appears that...
2
by: =?Utf-8?B?TmFjaA==?= | last post by:
I am new to .net can someone teranslate the foloowing in .net Ls and Lt will be listboxes. Sub ListCpSelected(Ls As Control, Lt As Control) 'Copies selected items from one list to another Dim I...
2
by: Tracey | last post by:
How can I convert to a string (what I thought was a string)? and/or How can I assign the value of a selected item in a list box to Label1.Text? using VB in VS2005. Thanks, Tracey I completed...
4
by: manch | last post by:
I need some help with this, just can't seem to get it straight. I need to write a loop that will add each item of a listbox to get a Sum of the numbers inside. I am using vb.net 2005
1
by: Shimna Thomas | last post by:
In the below code, I am trying to redirect to another page, depending on the value of the selected item in the listbox;but I am getting the error : "Cannot implicitly convert type'string ' to...
1
by: Grok | last post by:
Is this a feature of ListBox that when using a DataSource, the SelectedItem acts different? Added ListBox1 and ListBox2 to a form. ListBox1 is bound to a DataSource where DisplayedMember=name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.