Finding BindingSource.Position from Listbox Selection

R

Randy

Hi,
I'm have a form with a listbox and a few textboxes on it. Based on
the user's selection in the listbox, I want the bindingsource to
update the textboxes with the corresponding values. I have similar
code built for a combobox that works just fine, but when applying it
to a listbox bound to a dataview, I can't figure out how to return the
correct bindingsource index. No matter what item I select, my index
returns 0.

Private Sub lbUOM_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles lbUOM.SelectedIndexChanged

cn.Open()

Dim drv As DataRowView = CType(lbUOM.SelectedItem,
DataRowView)
tb.Text = drv.Item("USUOM").ToString

Dim index As Integer = bsUOM.Find("USUOM", tb.Text)
If index <> -1 Then 'it was found; move to that
position
bsUOM.Position = index
End If

cn.Close()
End If
End Sub

Can anybody see why this doesn't work? Is there a better way to
navigate the bindingsource based on a listbox selection? I don't see
this issue posted anywhere in this board.

Thanks,
Randy
 
C

Cor Ligthert[MVP]

Nick,

That goes automaticly as you databind the textbox to a table, and you do the
same for the combobox using the datasource, then the currencymanager will
set the current table-item in the textbox.

You even need a New DataView for not doing that.

I would use this newsgroup for information instead of the by you quoted one.
This is common stuff here.

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