Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hello , I am new at visual basic 2012 and i have an issue with the list box control selected item

I have a data base with 3 tables 1.Doctors 2.Names 3.NamesHolidays .
I create a data set with the 3 tables and their relations , i drag to the form the doctors Table as details.

I replace the NameId textbox with a combobox with the following parameters
• DataSource : NamesBindingSource
• DisplayMember : Description
• ValueMember : NameID
• SelectedItem : DoctorBindingSource - NameID
And i have a look up field filled up with the values that they are in the Names Table i select one and the NameID is stored to the doctorsTable.

After this i replace the NameHolidayID text with a listbox with the following parameters
• DataSource : FKHolidaysNamesNamesBindingSource
• DisplayMember : Date
• ValueMember : HolidayID
• SelectedItem : DoctorBindingSource - HolidayNameID

So now every time i choose a different doctor from the DoctorBindingNavigator Toolbar the selected name at the combo box is changed , the values to the listbox are changed to the right values for the specific name

But the problem is that the selected item at the ListBox is always the first item at the list and not the item that is stored at the HolidayNameID at the doctors Table.

I wrote no code the visual basic inserted a few lines of code to fill the tableadapters
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.HolidaysNamesTableAdapter.Fill(Me.PhysioDataSet.HolidaysNames)
Me.NamesTableAdapter.Fill(Me.PhysioDataSet.Names)
Me.DoctorTableAdapter.Fill(Me.PhysioDataSet.Doctor)
End Sub


I hope to describe the problem well...Thanks is advance for your time.
Posted
Comments
Aydin Homay 17-Jun-13 3:07am    
Could you tell me what you want exactly at just 1 row ?
JNDIONYSIM 17-Jun-13 14:29pm    
I will try to describe you the problem ,
I want to save the information for the doctors , I have a combo box witch is filled up with names to choose for the doctor name ,when i choose a name then a list box is filled up with dates for the specific name , and then i can choose one date from the listbox and save the DateID and nameId to the doctors table (In the data base there are two tables Names(Parent) and NamesDate(Child) ... Until now everything works perfect.
The problem is when i am viewing the doctors in the form then the combobox has the correct name that i saved , the listbox is filled up with the correct dates for the specific name but the selected value on the listbox is not the one that i saved in the DateID at the doctors table , is always the first item in the listbox.
kpolecastro 27-Jun-13 10:59am    
If your HolidayNameID reflects the index of the item you wish to select, you could use Listbox.SelectedIndex = HoldidaynameID

otherwise you could try

Listbox.SelectedItem = HolidayNameID

If you could describe a little more about exactly what you are trying to do, I may be able to assist you some more.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900