Re: vb.net ListBox Help

  • From: "Richard Thomas" <rthomas@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 30 Nov 2007 14:43:15 -0500

Hi Jamal:

Tried the below with the same results.

Note that the e-mailer is making things wrap in the wrong places, everything is ok in that respect.

Mabey I can't iterate the ListBox using the ListBox controls at all after binding it to something?

I wonder if only the nav for the DataTable or DataView is what works.for bound controls.

Here is the latest code:

Public Class frmStocksReport

dim Dt As StockFDataSet.StocksDataTable

Private Sub lbStocksReportNdx_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles lbStocksReportNdx.SelectedIndexChanged

MessageBox.Show( "Index is " & lbStocksReportNdx.SelectedIndex.ToString())

Note: The above still returns 0 for all ListBox entries

MessageBox.Show( _

DirectCast( _

lbStocksReportNdx.SelectedItem, DataRowView)("Ticker").ToString())

The Above still returns the ticker for the first entry in the ListBox.

By the way, I just dropped the ListBox on the form in the VS IDE and the events seem to be there as I am using them.



End Sub

Private Sub frmStocksReport_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dt = New StockFDataSet.StocksDataTable()

Dim StocksAdapter As New StockFDataSetTableAdapters.StocksTableAdapter()

Dt = StocksAdapter.GetAllRows()

lbStocksReportNdx.DisplayMember = "Name"

lbStocksReportNdx.ValueMember = "Ticker"

lbStocksReportNdx.DataSource = Dt

End Sub

End Class


----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, December 01, 2007 12:48 PM
Subject: Re: vb.net ListBox Help


Data binding should be able to do what you want.  In examining the code,
it appears that a right parenthesis should be moved after ToString()
rather than before it.  Also, should it read SelectedIndex.ToString()
rather than SelectedItem.ToString()?  When declaring the ListBox, did
you use the WithEvents keyword?

Jamal
On Fri, 30 Nov 2007, Richard Thomas wrote:

Date: Fri, 30 Nov 2007 08:09:29 -0500
From: Richard Thomas <rthomas@xxxxxxxxxxx>
Reply-To: programmingblind@xxxxxxxxxxxxx
To: programmingblind@xxxxxxxxxxxxx
Subject: vb.net ListBox Help

Hi Guys:
I bind a ListBox to a DataTable in a Load Event and load it. This works fine. I can arrow up and down and the entries are correct.
I can not read the entries in the ListBox into a TextBox.
Even though I arrow up and down the list and the IndexChanged event fires the TextBox always shows the first entry in the list.
Public Class frmStocksReport
dim Dt As StockFDataSet.StocksDataTable
Private Sub lbStocksReportNdx_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles lbStocksReportNdx.SelectedIndexChanged
MessageBox.Show( "item is " & lbStocksReportNdx.SelectedItem).ToString()
Note: the above always shows the index as 0.' tbDescription.Text = _
MessageBox.Show(  _
DirectCast( _
lbStocksReportNdx.SelectedItem, DataRowView)("Ticker").ToString())
Note: The above always shows the first item's Ticker Symbol.
End Sub
Do I somehow need to synch the underlying DataView or DataTable to the ListBox Selected Item somehow?
Should I scrap the whole DataBinding senario?
Any Ideas?
Rick Farmington Mich. USA

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: