Go To Record

tbpowers

Active member
Joined
Dec 12, 2011
Messages
41
Programming Experience
Beginner
I have a combobox, which is populated with the unique id's of my records. How do I get it to go to the record when an id is chosen from the drop down? Any help will be greatly appreciated.
 
Populate a DataTable with the data, bind that DataTable to a BindingSource and then bind that to the ComboBox. When you make a selection in the ComboBox, any other controls bound to the BindingSource will update with the other fields from the corresponding record, e.g.
myBindingSource.DataSource = myDataTable

With myComboBox
    .DisplayMember = "ID"
    .ValueMember = "ID"
    .DataSource = myBindingSource
End With

myTextBox.DataBindings.Add("Text", myBindingSource, "Name")
 
Worked perfectly! Any idea how I can get it to start at a new record, but still give the user the option of chosing an existing record from the drop down? I tried adding the following code at form load, but it crashes when I try to select an existing record from my combobox.

Me.REPAIRBindingSource.AddNew()
 
First up, a crash is an unhandled exception and if there's an exception then there's an error message. If you want us to help you with an error then you should always provide that error message because there's no guarantee that we'll have any idea what the problem is without it. In this case, I think I know though.

I would guess that your table has at least one non-nullable field. When you call AddNew a new row is created but not immediately added to the underlying table. When you select a different record, the new record gets added to the table. If the user hasn't set any of the fields in the new record then any fields that are non-nullable are invalid. You have to account for that possibility in your code.
 
That is what is happening. I have several fields that can not contain a nullable field. How do I program around this? I appreciate the help.
 
If you want the user to be able to select an existing record without populating a new record then don't add a new record by default. If the user wants a ne record then let them tell the app that they want a new record. That's how applications work pretty much universally.
 
How do I set it up to open at a blank record then? That way the user can select an existing record or click the add new record button. I do not necessarily want the app to open showing the last record.
 
Really? There is no way to program it to allow the user to create a new record or open an existing record? All the third-party apps we have do so.
 
You're really trying to take something simple and make it complicated. If you don't want the user to see any data to begin with then don't retrieve any data to begin with. If you're going to retrieve all the data up front then what purpose does it server to hide that data from the user? These applications that you mention probably don't actually retrieve any data until the user requests them to.
 
Back
Top