Need help with databinding

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi everyone, I need some help with the following it is quiet simple really but its been really stressing me out as I have spent many hours trying to figure out how to do it. I have a form which is databinded to a table, in the form there is a listbox, 2 buttons and 2 textboxes. The idea of the program is simple, in the listbox it shows the description of the item (in any random order), the two textboxes are binded to the database and the first textbox shows the description of the item, and the second textbox shows a specific number which is related to the item.

Also the buttons are placed next to the listbox and their role is simple, one is an ‘up’ button and one is a ‘down’ button. They navigate through the chosen item in the listbox, however they also move on to the next/previous item in the textbox, for example I have included the following coding which is with the down button:

dbindingmanager.Position += 1

'Make the selected item go lower in listbox1
If Me.listbox1.SelectedIndex <> Me.listbox1.Items.Count - 1 Then
Me.listbox1.SelectedIndex = Me.listbox1.SelectedIndex + 1
End If

The part I need help with is there a way in which the item in the listbox matches the item in the textbox, the part im having trouble with is the up and down buttons only move on to the next/previous record in the textbox and not matching the same item which is shown in the listbox, I need the item that is showing in the listbox to be the same as the item in the textbox. I have included a print screen of my program, if you can give me any suggestions or help me out I would really appreciate it.

Thanks alot.

455soas.jpg


(By the way the above is incorrect as I have entered the text in the two textboxes) but I hope you get my drift.
 
So far I have the following on the up and down buttons

dbindingmanager.Position -= (Listbox1.SelectedItem)

dbindingmanager.Position += (Listbox1.SelectedItem)

but, it keeps breaking. I know it cant be much difficult than this.
 
If the listbox binds through the same binding manager as the text boxes, then it will derive its selecteditem from the Position of the dbindingmanager

Ensure that you havent bound your listbox straight to the table.. Bind it to the same manager as the textboxes

Now, moving the list selection should change the textboxes, and clicking the buttons should move the list selection
 
Thanks CJard for your suggestion, you see I tried explaining my question to you by missing some points I know it was stupid but im sorry. You see in my program I have 2 listbox's, the first listbox is how you have described it, it has been databinded just as the textboxes, so when I move onto the next record the textbox and the listbox moves onto the next record.

However on my program I have an 'Add' and 'Remove' button, the first adds the item to the second listbox, the second button removes the item from listbox2. The code that I have used to add the item from listbox1 to listbox2 is as follows:

listbox2.Items.Add(listbox1.GetItemText(listbox1.SelectedItem)).

Now comes the difficult part, the part i need help with is I want the priginal textbox to match the items in listbox2. For example the items in listbox2 can be in any random order, and whatever is in listbox2 I want to match in the textbox, just like you have suggested in the above, however I cannot databind the second listbox as it throws an error.
 
Can you liken your dialog here to anything else that I will be familiar with? I cant quite understand what is to be happening..
 
Sure CJard:

2hqceqa.jpg


I hope the above gives you and others a better idea of the program. The up and down buttons with listbox 1 show the same item as the textbox as you can see from the above, however what i need is to 'show' the selected item in listbox 2 in the textboxes if you understand. For example the above textbox should show 'Item 7'. So in a way listbox 1 and listbox2 are connected to the textbox.
 
It looks like quite a confusing UI.. i can see why the textboxes show Item6.. But why should they show Item 7? surely then, they would be on the other side?

If they already show item 6, can you not replicate this on the other side for the other listbox?
 
Problem is solved, i have just matched the items in listbox2 and listbox1.

Thanks CJard for me actually tackling this problem it was down 2 u, ur words made me realise what needed to be done and its all working nice one.

Thanks again!
 
Last edited:
Back
Top