Stuck with retrieving values from a listbox

  • Thread starter Thread starter Alex A via .NET 247
  • Start date Start date
A

Alex A via .NET 247

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.
 
Hi,

Dim drv As DataRowView = ListBox1.SelectedValue

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

Ken
-------------
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.
 
Back
Top