Listbox Problem

  • Thread starter Thread starter Glen Wolinsky
  • Start date Start date
G

Glen Wolinsky

I have two virtually identical listbox controls on a tabPage in my
application. I bind a small datatable to each one when a new project
(my data) is selected from a treeview control (this works fine).

When I select the first project, the data is retrieved without a
problem and the datatables are properly bound to both listboxes. The
first listbox has a "SelectedIndexChanged" event wired to it which
also works fine.

Now, here's the wierd part: When I select a different project, the
data is retreived and the datatables are properly bound to both
listboxes. HOWEVER, the first listbox doesn't show the data!!!!! The
data IS THERE, but it's invisible!!! You can even select an item, and
the select even fires properly with the correct data.

EVEN WIERDER is that if I un-wire the "SelectedIndexChanged" event the
problem goes away!!!! Of course, now my select events don't work.

This is VERY strange.

Any help would be greatly appreciated.

Sincerely,
Glen Wolinsky
 
Hi Glen,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that when you change the datasource
from one table to another, the data will not show in the first listbox.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I can not reproduce the problem.
Here is my test code.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = Me.DataSet11.Customers
Me.ListBox1.DisplayMember = "Address"
Me.ListBox2.DataSource = Me.DataSet11.Customers
Me.ListBox2.DisplayMember = "CompanyName"
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
Me.OleDbDataAdapter2.Fill(Me.DataSet11)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.ListBox1.DataSource = Me.DataSet11.Employees
Me.ListBox1.DisplayMember = "FirstName"
Me.ListBox2.DataSource = Me.DataSet11.Employees
Me.ListBox2.DisplayMember = "LastName"
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox("ListBox1_SelectedIndexChanged")
End Sub

Please apply my suggestion above and let me know if it helps resolve your
problem.

Also can you povide a simple reproduce sample for us to do further
troubleshooting?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I fixed the problem by using the following code for both listbox
controls when initializing my form:

lbxAssignments.BindingContext = Me.BindingContext
lbxOtherAttys.BindingContext = Me.BindingContext

I have limited understanding as to what this does, but it fixed the
problem.

Thanks,
Glen
 
Glen said:
I fixed the problem by using the following code for both listbox
controls when initializing my form:

lbxAssignments.BindingContext = Me.BindingContext
lbxOtherAttys.BindingContext = Me.BindingContext

I have limited understanding as to what this does, but it fixed
the problem.


Maybe this helps:
http://msdn.microsoft.com/library/d...on/html/vboriWindowsFormsDataArchitecture.asp


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi Glen,

Did the link Armin post help you?

If you still have any concern on this issue, please feel free to post here
and I will work on you with that.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top