ComboBox - databound question. -newbie

M

Miro

VB.net 2005 Expess - and an SQL Express db

I cant seem to figure out a way to bind a ComboBox properly.
I have set up a dummy app with a dummy file

I have 2 datatables,

Table: LoginUsers
LoginID int autoincrement allownulls = false
LoginName Varchar15


Table: People
PersonID int autoincrement allownulls = false
PersonName Varchar15
LoginID int allownulls = true

Relationship is set up with People.LoginID to LoginUsers.LoginID

This way I can have "people" in a list, and assign them generic Login Names
if they have a loginID. Otherwise they cant login. This project really
has no point but im trying to teach myself how to use multi tables in 1
form.

First step: I just have 2 forms.
LoginUsers form - this works fine, I can add and delete LoginUsers into the
datafile.

My People form does not.
I went to my Datasources tab and dragged over the Person.PersonName
(textbox)and Person.LoginID which is a combobox.

I am trying to have the Combobox bound to People.LoginID, but display
LoginUsers.LoginName
When a user selects a LoginName from the list, it should internally write
the LoginUsers.LoginId to the People.LoginID field - but always displaying
the LoginUsers.LoginName

I have tried the combobox -databindings SelectedItem / Selected Value,
text and DataSource and cant figure out what objects to set where.

I have even downloaded this example from the help:
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vbcode/html/78785cc4-5f9d-45d9-a0c9-59f838a49c31.htm

But they do this internally through code - and with an arraylist. Im trying
at first to try to set something like this up using the properties on the
forms designer - not by code. - babyseps :)

Can someone help me out please.

Thanks,

Miro
 
C

Cor Ligthert [MVP]

Hi,

A combobobox has 4 items to bind. The normal databinding to the result and
the way to bind to the source.

The databinding can be the best done using the selected value however be
aware that especially this part of the combobox has been from the first day
very buggy. (there are more bugs especially in the eventhandling).

The binding to the combobox itself can be done using

The combobox.Datasourse = yourtable
The combobox Displaymember = your displayfield
The combobox Valuemember = your id

Cor
 
M

Miro

Hi Cor,

Thanks for the bug info, however I still cant get the simple dropdown
working without any errorhandling.

The closest I have so far is this:

ComboBoxProperties:
ComboBox.Datasource = LoginUsers.BindingSource
ComboBox.DisplayMember = LoginUsers.LoginName
ComboBox.(Databindings).SelectedItem = LoginUsersBindingSource - LoginName
ComboBox.(Databindings).SelectedValue = LoginUsersBindingSource - LoginID
ComboBox.(Databindings).Text = PeopleBindingSource - LoginID

So as I move up and down my datagrid this field does get updated...but the
text that is displayed is the LoginID which is the int. What I am looking
for is to display the Name from the LoginUsers Table, while in the Peoples
Table.

If i change the ComboBox.(Databindings).Text to = LoginUsers.BindingSource -
LoginName, then i dont get anything working. So Im closer with the above
example. -
Is this one of the things you were talking about buggy? -That you cant
properly databind it and must do it all manually through code?

Thanks,

Miro
 
M

Miro

Thank you Cor,

I misread your earlier answer with the Valuemember.

Sorry for the late reply - I did read your reply but have had some computer
issues the last couple days.

Thank you again for the reply.

Miro
 

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