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

Stuck with retrieving values from a listbox

Hello all. I'm new to .NET and I am stuck and I just cannot getthis to work (even after much searching).

I have a listbox populated by data from an Access Database. Themanner in which I fill the listbox is as follows:

\\\\\\\\
dsClosedPos.Clear()

dbAdapter.SelectCommand = New OleDbCommand
dbAdapter.SelectCommand.Connection = dbConnect
dbAdapter.SelectCommand.CommandText = _
"SELECT * FROM qryClosedOutPositions"
dbAdapter.SelectCommand.CommandType = CommandType.Text

dbConnect.Open()
dbAdapter.SelectCommand.ExecuteNonQuery()
dbAdapter.Fill(dsClosedPos, "ClosedPos")
dbConnect.Close()

lstClosedPos.DataSource =dsClosedPos.Tables("ClosedPos").DefaultView
lstClosedPos.DisplayMember = "TRADED"
\\\\\\

This populates the listbox (lostClosedPos) with the results fromthe query. I am tryint to retrieve the SelectedValue when auser makes a change. However, using something along the linesof lstClosedPos.SelectedItem.Tostring() orlstClosedPos.SelectedValue does not work. I need the value ofthe listbox selection as a variable for a query.

Any help would be appreciated.

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>FD3bt6WkBEWvgpEvqiDgpA==</Id>
Jul 21 '05 #1
2 1389
Hi,

Dim drv As DataRowView = ListBox1.SelectedValue

Trace.WriteLine(drv.Item("TRADED").ToString)

Ken
-------------
"Alex A via .NET 247" <an*******@dotnet247.com> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Hello all. I'm new to .NET and I am stuck and I just cannot get this to
work (even after much searching).

I have a listbox populated by data from an Access Database. The manner in
which I fill the listbox is as follows:

\\\\\\\\
dsClosedPos.Clear()

dbAdapter.SelectCommand = New OleDbCommand
dbAdapter.SelectCommand.Connection = dbConnect
dbAdapter.SelectCommand.CommandText = _
"SELECT * FROM qryClosedOutPositions"
dbAdapter.SelectCommand.CommandType = CommandType.Text

dbConnect.Open()
dbAdapter.SelectCommand.ExecuteNonQuery()
dbAdapter.Fill(dsClosedPos, "ClosedPos")
dbConnect.Close()

lstClosedPos.DataSource =
dsClosedPos.Tables("ClosedPos").DefaultView
lstClosedPos.DisplayMember = "TRADED"
\\\\\\

This populates the listbox (lostClosedPos) with the results from the query.
I am tryint to retrieve the SelectedValue when a user makes a change.
However, using something along the lines of
lstClosedPos.SelectedItem.Tostring() or lstClosedPos.SelectedValue does not
work. I need the value of the listbox selection as a variable for a query.

Any help would be appreciated.

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>FD3bt6WkBEWvgpEvqiDgpA==</Id>
Jul 21 '05 #2
Hi,

Dim drv As DataRowView = ListBox1.SelectedValue

Trace.WriteLine(drv.Item("TRADED").ToString)

Ken
-------------
"Alex A via .NET 247" <an*******@dotnet247.com> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Hello all. I'm new to .NET and I am stuck and I just cannot get this to
work (even after much searching).

I have a listbox populated by data from an Access Database. The manner in
which I fill the listbox is as follows:

\\\\\\\\
dsClosedPos.Clear()

dbAdapter.SelectCommand = New OleDbCommand
dbAdapter.SelectCommand.Connection = dbConnect
dbAdapter.SelectCommand.CommandText = _
"SELECT * FROM qryClosedOutPositions"
dbAdapter.SelectCommand.CommandType = CommandType.Text

dbConnect.Open()
dbAdapter.SelectCommand.ExecuteNonQuery()
dbAdapter.Fill(dsClosedPos, "ClosedPos")
dbConnect.Close()

lstClosedPos.DataSource =
dsClosedPos.Tables("ClosedPos").DefaultView
lstClosedPos.DisplayMember = "TRADED"
\\\\\\

This populates the listbox (lostClosedPos) with the results from the query.
I am tryint to retrieve the SelectedValue when a user makes a change.
However, using something along the lines of
lstClosedPos.SelectedItem.Tostring() or lstClosedPos.SelectedValue does not
work. I need the value of the listbox selection as a variable for a query.

Any help would be appreciated.

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>FD3bt6WkBEWvgpEvqiDgpA==</Id>
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
3
by: Chris Thunell | last post by:
I have a Listbox on an vb aspx web page. When i select something in the listbox i do not get a selected value or selected index. The selected index is always -1. Any thoughts would be greatly...
6
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
2
by: Jay Banks | last post by:
I'm working on a project that lists a few hundred items in a checked listbox. The listbox entries are all backed up by a structure, and only the descriptiong of the structure is shown in the...
3
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
1
by: Alex A via .NET 247 | last post by:
Hello all. I'm new to .NET and I am stuck and I just cannot getthis to work (even after much searching). I have a listbox populated by data from an Access Database. Themanner in which I fill the...
0
by: Phijo | last post by:
Hello, I'm a Java developer but brand new to ASP (i have done some of the tutorials) so I have some ASP programming background however I cannot find the cause or the fix to this problem. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.