How to update fields on windows form after updating value in combobox?

adi2015

Member
Joined
Mar 4, 2015
Messages
17
Programming Experience
3-5
Hi,

I have combobox on windows form, named 'Patient ID'. I would like, when user apdates this field, for other fields on that form to be updated. Please see image attached.

question.jpg
Can anyone help me with this?

Thank you.
Adi
 
It would help if we knew where this data is coming from. I'm going to guess that it's coming from a database originally. Have you already retrieved all the data or are you intending to retrieve it as required?
 
Very basic answer, but I was thinking you might want to just set up a handler for that textbox.

Just create a sub
public sub foo(sender as object, e as eventargs) handles textbox1.keydown
'if e.keys is keys.enter
'maybe validate patient id
'if valid update other fields
'if not valid tell the user somehow
'else do nothing
end sub


Really basic pseudo code there, but the handler could probably get you started.

Aside from that, what jmc said about where your data is coming from is also important, and it will determine how you actually retrieve the data within that little pseudo-coded function I showed you
 
@jmcilhinney

Hi, data is coming from database originally, from table "Patients" which contains fields Patient_ID, Name, Surname, Address. It is very simple. I am intending to retrieve data as it is required..

BR,
Adi
 
Very basic answer, but I was thinking you might want to just set up a handler for that textbox.

Just create a sub
public sub foo(sender as object, e as eventargs) handles textbox1.keydown
'if e.keys is keys.enter
'maybe validate patient id
'if valid update other fields
'if not valid tell the user somehow
'else do nothing
end sub


Really basic pseudo code there, but the handler could probably get you started.

Aside from that, what jmc said about where your data is coming from is also important, and it will determine how you actually retrieve the data within that little pseudo-coded function I showed you

Hi jwcoleman87,

thank you, your post helped me form a picture but I dont understand what code I should use for one simple task: when I user updates Patient_IDComboBox, field NameTextBox should show name of the patient?

BR,
Adi
 
That part is what jmc is touching on.

to assist you with this we need to see the kind of code you're already using to talk to this database. Are you using LINQ? ADO? Something else? Are you able to query your database from your code? If so, how are you doing it?
 
Hi jwcoleman87,

thank you very much for your reply!
Perhaps I didn't explained everything in detail and that is reason why, unfortunately can't use code you suggested. All my importan data is set in "Patients" table. Please see image bellow, I think it explains it better. Can you help me achieve that result?

BR,
Adi

example.jpg
 
Is that a table on your form (or contained in memory in your application) or a table in a database?

I see what you did I think. You used the form to select a datasource for that list box.

I recommend getting your database into your code in a way that is accessible by all of your code.

You should check out Project->Add New Data Source...

And use the object it creates to be able to access your data. This is probably the simplest way to do what you're trying to do.
 
Last edited:
Is that a table on your form (or contained in memory in your application) or a table in a database?

I see what you did I think. You used the form to select a datasource for that list box.

I recommend getting your database into your code in a way that is accessible by all of your code.

You should check out Project->Add New Data Source...

And use the object it creates to be able to access your data. This is probably the simplest way to do what you're trying to do.

Hi,

it is table in datababase. I have a dummy form on which I want to have one simple combobox. After user chooses some value (HEALTH_ID) from comobox, that three fields (name, surname, address) on dummy form, to be filled with related data from table "Patients" from database with related HEALTH_ID. If you choose HEALTH_ID no. 1 three fileds will show Jack Nicholson Hollywood..

BR,
Adi
 
As jwcoleman87 says, add data source. Afterwards in Data Sources window select the table and change binding mode from DataGridView to Details. Drag the table to form. Now all controls and databindings are configured for you, including form load code to fill data from database. All you need to add now is the ComboBox, in designer configure its databinding manually, for DataSource select the existing BindingSource, in DisplayMember select the field you want to list (HEALTH_ID). Done.
 
Back
Top