Listbox oddity

G

Guest

I'm having some trouble with a listbox on a Windows form.

Initially it populates fine. I have another listbox (listbox1) and when it's
index changes, listbox2 is repopulated.
I have a textbox that displays what is selected in listbox2.
It is rare that listbox2 has any data right now.
So if I click through listbox1, and there is no data to put in listbox2,
it's fine.
When I click on the first item in listbox1 that does have data to display in
listbox2, it's fine.
Then, when I move to another item in listbox1, my listbox2 never changes.
Whatever was displayed in there the 1st time, remains.
The wierd thing is, the textbox, that is populated with the code:

dim drv as datarowview
drv = Me.listbox2.SelectedItem

Me.txtbox1.Text = drv("STR_AMEND_NO").ToString

this displays the correct data...
and if there are supposed to be greater than 1 items in listbox2, but only 1
is displaying (from a previous selection), i can still click on 1 or 2 items
in listbox2 (even though I can't see them) and the correct data displays in
txtbox1.

I'm not sure if I've given enough information to go on here...but I'm very
frustrated!!

TIA!
Amber
 
C

Cor Ligthert [MVP]

Amber,

For a listbox is at least important how you populate it.

Can you tell us that for both?

Cor
 
M

Morten Wennevik

Hi Amber,

It seems to be that you are forgetting to clear the data in listBox2 when the item in listBox1 change, but as Cor said, please tell us how you populate your ListBoxes (code sample).
 
G

Guest

What code would I use to clear my listbox?

I populate my listboxes as follows.
lboxCP = listbox1 in my previous post
lstAmendments= listbox 2

this sub is called whenever the index of listbox1 (lBoxCP) is changed:

Private Sub getCPAmends()

Dim permit As String
Dim drv As DataRowView

drv = lBoxCP.SelectedItem

permit = drv("ID_CUTTING_PERMIT")
_datasetAmend.Clear()

lstAmendments.DataSource = Nothing

_datasetAmend = _opmanager.getCPAmend(permit)
** note that here I call a function that uses MS Application Blocks add-in
to populate my dataset **

_dataviewAmend = New DataView(_datasetAmend
..Tables("vwCuttingPermitAmendApp"), "", "STR_AMEND_NO",
DataViewRowState.CurrentRows)

Me.lstAmendments.DataSource = _dataviewAmend
lstAmendments.DisplayMember = "STR_AMEND_NO"

Is this enough information??
TIA!
Amber
 
C

Cor Ligthert [MVP]

Amber,

Why not try what happens when you set this statement not in one line in its
constructor, however one by one by setting the properties. I think that it
makes your problem more clear
_dataviewAmend = New DataView(_datasetAmend
.Tables("vwCuttingPermitAmendApp"), "", "STR_AMEND_NO",
DataViewRowState.CurrentRows)
Just my thought,

Cor
 
M

Morten Wennevik

Hi amber,

I'm afraid I'm not sure what happens although I think I have heard of something similar before (at least regarding being able to select invisible items).

If you are running McAffee antivirus it might be worth trying to update it.

If the code is called by windows in an event it may also be that an exception is swallowed. Put the code inside a try catch block.

Since the question is related to databases/datasources you might want to try this newsgroup

microsoft.public.dotnet.framework.adonet

or the VB newsgroups

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.data
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top