need help: list box showing item selected when none are

B

Brian Henry

I have a list box bound to a data set, of course the datasource,datamember,
and valuemember are set, i tell it selecteditem = -1 to make nothing
selected, select mode is set to only one item at a time. When the list fills
the first item in the listbox has a background rectangle drawn but no focus
rectangle (this is NOT a custom drawn listbox, just a standard one).. now i
did set -1 as the selected item, but if i tab to the item the focus
rectangle is now showing over the background rectangle on the 1st item, then
when i tab off the listbox now nothing is selected like it should of been to
start with... what would cause this?! thanks.. the listbox is in a custom
control which is then placed onto a form... if i do it only on a form by
itself it works fine... but when its in a custom control it causes this
problem..
 
B

Brian Henry

same result with selected index.... just switch it in the test project i
posted and see :\
 
C

Cor

Hi Brian,

I thought in your message that you did mean that little listbox bellow, but
you did mean the listbox in the usercontrol.

You have bound that listbox in the usercontrol to that dataclass USState

And in your form you are filing that dataclass

And therefore the selectedindex is affected.

After filing of that dataclass you can set the usercontrol selectedindex

UserControl11.ListBox1.SelectedIndex = -1

You will see that it is deselected.

I hope this helps?

Cor
 
B

Brian Henry

how about when the user control is in a ClassLibary and being refrenced
though that DLL into the form in the application... then i cant do the
usercontrol1.listbox1.selectedindex = -1 because i then no longer have the
contorls inside the user control available to me.... thats my problem at
this point...
 
C

Cor

Hi Brian,

Do you mean that you want something like this in your usercontrol?

Private Sub ListBox1_BindingContextChanged(ByVal _
sender As Object, ByVal e As System.EventArgs) _
Handles ListBox1.BindingContextChanged
ListBox1.SelectedIndex = -1
End Sub

Cor
 

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