Help on displaying combobox items

M

max

Hello,
I have a VS2005 framework and ado.net.
I have an access db with two tables:
1) Patients;
2) Doctors.
The 'Patients table is already filled by a long list of records (coming from
an old access db) in 3 columns: ID, Name, Doctorname (for that patient);
The Doctors table is filled by only a column: Doctorname, which is a current
list of doctors working here at now.
I want put on a form just the 'Patient' table, with a combobox for Doctor
field that must display the actual doctor for the selected patient, and the
list (dropdown) for the Doctor's name coming from the 'Doctor' table, which
could be different from the Doctor's names, meaning that this list reflects
only the actual doctors working here, while in the patients table (old since
5 years) there are also some doctors that are not working here anymore. It
means that if I add a new patient, I can have only the actual doctor as the
current list (in the dropdown) and not the old. The same is if I want to
change the doctor for a patient which was cured from a doctor which doesn't
work here now.
I put the following combination in the databinding properties of this
combobox:
Datasource: tblDoctorsbindingsource
Display member: Doctorname
Value member: Doctorname
Selected value: tblPatientsbindingsource-Doctorname
When I run the project, and go scrolling records, in the Doctor field I get
the right actual doctor for the patient, but when I click on the arrow, I
see a confused list of doctors, with some name in the beginning and then
repeated below. The list was sorted at the beginning.
What does it mean?
Any help would be welcomed.
Thanks.
Max
 
G

Guest

Dear Max?
use Join Query Table right?
of course you will see redundant data.

Solution [ Redundant Data]:
1. use Distinct Statement On SQL Query.

Solution [Doctor Resign]
1. Add New Field To Doctor Table

[Doctor]
iDoctorID int <Primary Key> Integer [if you want it]
DoctorName <this is your doctor field name right?>
cAvailable <If 1 then doctor available If 0 Then Doctor Resign> Char
Datatype Length 1

I wish i can help ;)
[Doctor]
 
M

max

max said:
Hello,
I have a VS2005 framework and ado.net.
I have an access db with two tables:
1) Patients;
2) Doctors.
The 'Patients table is already filled by a long list of records (coming
from an old access db) in 3 columns: ID, Name, Doctorname (for that
patient);
The Doctors table is filled by only a column: Doctorname, which is a
current list of doctors working here at now.
I want put on a form just the 'Patient' table, with a combobox for Doctor
field that must display the actual doctor for the selected patient, and
the list (dropdown) for the Doctor's name coming from the 'Doctor' table,
which could be different from the Doctor's names, meaning that this list
reflects only the actual doctors working here, while in the patients table
(old since 5 years) there are also some doctors that are not working here
anymore. It means that if I add a new patient, I can have only the actual
doctor as the current list (in the dropdown) and not the old. The same is
if I want to change the doctor for a patient which was cured from a doctor
which doesn't work here now.
I put the following combination in the databinding properties of this
combobox:
Datasource: tblDoctorsbindingsource
Display member: Doctorname
Value member: Doctorname
Selected value: tblPatientsbindingsource-Doctorname
When I run the project, and go scrolling records, in the Doctor field I
get the right actual doctor for the patient, [...]

Sorry, I can't display the 'old doctors', I just see a blank field. It's a
one more trouble for me.
but when I click on the arrow, I see a confused list of doctors, with some
name in the beginning and then repeated below. The list was sorted at the
beginning.
What does it mean?
Any help would be welcomed.
Thanks.
Max

Please help.
 
R

RobinS

So basically your problem is that you want the doctor
dropdown to only allow the user to select doctors currently
in practice, but you also want the history data to display
accurately.

Is that right?

Robin S.
 
M

max

RobinS said:
So basically your problem is that you want the doctor
dropdown to only allow the user to select doctors currently
in practice, but you also want the history data to display
accurately.

Is that right?

Robin S.

Yes RobinS! That's it!
Thanks.
 
R

RobinS

How do you know the doctor no longer works there?
Is there an indicator in the table?

Robin S.
---------------------------
 
M

Max

I just see a blank field when I select records with old doctor. In dataset
explorer, the table was set in 'details' view; the column 'Patients' is a
textbox, the column 'Doctors' is a combobox; then I dragged it in the form.
When I scroll the records through the bindingnavigator and I reach a
patients with old doctor, the field remains blank.
Then I tried to drag, in the same form, the same table using the 'datagrid'
view instead; gone to 'column modifies' by clicking the small top right
arrow in the grid, changed the property values for the 'Doctor' column, in
the Data properties as this:
Datasource: tblDoctorsBindingSource
Display member: Doctors
Value member: Doctors
When running the application, going through records till I find a patients
with old doctor, and move the mouse in the (blank) doctor combobox, I get
the following error:
Exception in DataGridView: System.Argument.Exception: DataGridViewComboBox
value not correct. Handle the event by DataError. (I'm translating to
English, probably you'll see a slightly different message).

Thanks Robin.
 
R

RobinS

Okay, so let me see if I can specify this back to make sure I
understand.

You have two tables:
patients: ID, Name, DoctorName
doctors: DoctorName [only has doctors currently working there]

You want to put the patients on a form with a dropdown for doctor.
If the doctor is not in the [doctors] table, you would still like it
to show up, but you don't want them to be able to select the doctor
from the dropdown list.

But the dropdown list should only have doctors from the [doctors] table,
i.e. those who are currently working here.

Do I have that straight?

You have a BindingSource called tblDoctorsBindingSource which I presume
points at the [doctors] table as a data source.

You are trying to use the following for a combobox:
datasource = tblDoctorsBindingSource
displaymember = DoctorName
valuemember = DoctorName
SelectedValue = DoctorName from the tblPatientsBIndingSource.

I'm not going to deal with the DataGridView thing at this point.
I'm just going to think about having the combobox on the screen,
and then you can put it in a DGV if you want to.

So the problem is the doctors that no longer work there.
When you display a patient that has one of those doctors, the
combobox goes blank.

I put together a test project, and found this to be true, which
didn't surprise me. If you are going to use data binding, it
won't show the non-current doctors because they are not in the
list you are using.

So now what do you do? Here's some ideas in descending order of
usefulness.

(1) Change the Doctor to a textbox and bind it and disable it
for input and put a label on it calling it "Last Doctor Seen".
Put a combobox next to it of the new and valid doctors and
call it "Current Doctor". If it doesn't display, they don't have one.

So you bind LastDoctorSeen to the DoctorName in the patients
table. You bind the CurrentDoctor the way you have it now.
When they select a CurrentDoctor, it should fill in the LastDoctorSeen
to the same value.

(2) Change the Doctor to a textbox and bind it and disable it
for input. Put a button next to it <Select Doctor> that shows
a form they can use to select a doctor.

(3) Add all the doctors to the dropdown list. There are a multitude
of ways to accomplish this: join the data tables, create a generic
list, etc.. Then if they try to change it, check and see if the
doctor is valid, and if it's not, don't let them save it until
they fix it.

Frankly, #1 seems like the best option, especially if you want
to make sure each patient has a valid current doctor.

I would have structured my tables differently, but maybe you don't
have control over that.

Good luck. Hope this helps.
Robin S.
 
M

max

Hello.

RobinS said:
Okay, so let me see if I can specify this back to make sure I understand.

You have two tables:
patients: ID, Name, DoctorName
doctors: DoctorName [only has doctors currently working there]

You want to put the patients on a form with a dropdown for doctor.
If the doctor is not in the [doctors] table, you would still like it
to show up, but you don't want them to be able to select the doctor
from the dropdown list.

But the dropdown list should only have doctors from the [doctors] table,
i.e. those who are currently working here.

Do I have that straight?

You got it!
You have a BindingSource called tblDoctorsBindingSource which I presume
points at the [doctors] table as a data source.

You are trying to use the following for a combobox:
datasource = tblDoctorsBindingSource
displaymember = DoctorName
valuemember = DoctorName
SelectedValue = DoctorName from the tblPatientsBIndingSource.

I'm not going to deal with the DataGridView thing at this point.
I'm just going to think about having the combobox on the screen,
and then you can put it in a DGV if you want to.

So the problem is the doctors that no longer work there.
When you display a patient that has one of those doctors, the
combobox goes blank.

I put together a test project, and found this to be true, which
didn't surprise me. If you are going to use data binding, it
won't show the non-current doctors because they are not in the
list you are using.

This is what I can't understand: if my combobox binds to tblPatientsSource
(in the 'Selected value' property) , it should display *only* the values
coming from the 'Patients' table, therefore the 'old doctor' items only...
So now what do you do? Here's some ideas in descending order of
usefulness.

(1) Change the Doctor to a textbox and bind it and disable it
for input and put a label on it calling it "Last Doctor Seen".
Put a combobox next to it of the new and valid doctors and
call it "Current Doctor". If it doesn't display, they don't have one.

So you bind LastDoctorSeen to the DoctorName in the patients
table. You bind the CurrentDoctor the way you have it now.
When they select a CurrentDoctor, it should fill in the LastDoctorSeen
to the same value.

The #1 solution is what I'm using now. It's an elegant way to skip this
issue. But, when I change the doctors from the combobox, the text box
doesn't update immediatly, I still see the 'old doctor name' until I click
to the Save icon on the bindingnavigator...
(2) Change the Doctor to a textbox and bind it and disable it
for input. Put a button next to it <Select Doctor> that shows
a form they can use to select a doctor.

(3) Add all the doctors to the dropdown list. There are a multitude
of ways to accomplish this: join the data tables, create a generic
list, etc.. Then if they try to change it, check and see if the
doctor is valid, and if it's not, don't let them save it until
they fix it.

Frankly, #1 seems like the best option, especially if you want
to make sure each patient has a valid current doctor.

I would have structured my tables differently, but maybe you don't
have control over that.

Good luck. Hope this helps.
Robin S.

Thanks Robin.
 
R

RobinS

This is what I can't understand: if my combobox binds to
tblPatientsSource (in the 'Selected value' property) , it should
display *only* the values coming from the 'Patients' table, therefore
the 'old doctor' items only...

That's because it is double-bound. It also binds to the doctor table.
This means it won't show any entries not in the doctor table. It's
not like a right join, where it will show them whether or not they
are in the table to which you bound the control.
The #1 solution is what I'm using now. It's an elegant way to skip
this issue. But, when I change the doctors from the combobox, the text
box doesn't update immediatly, I still see the 'old doctor name' until
I click to the Save icon on the bindingnavigator...

The textbox should update when you tab out of the
combobox after selecting it. The Validate event isn't
called until you exit the field, and that's when the
databinding responds.

I hope you are calling the Validate() when they hit
Save. If they are editing a control on the screen and they
hit save, this ensures that the field they were editing is
saved. A call to EndEdit pushes the data from the controls
down to the data source, and then presumably you are doing
some kind of Update method on the dataset.

Good luck.
Robin S.
-----------------------------------

max said:
Hello.

RobinS said:
Okay, so let me see if I can specify this back to make sure I
understand.

You have two tables:
patients: ID, Name, DoctorName
doctors: DoctorName [only has doctors currently working there]

You want to put the patients on a form with a dropdown for doctor.
If the doctor is not in the [doctors] table, you would still like it
to show up, but you don't want them to be able to select the doctor
from the dropdown list.

But the dropdown list should only have doctors from the [doctors]
table,
i.e. those who are currently working here.

Do I have that straight?

You got it!
You have a BindingSource called tblDoctorsBindingSource which I
presume
points at the [doctors] table as a data source.

You are trying to use the following for a combobox:
datasource = tblDoctorsBindingSource
displaymember = DoctorName
valuemember = DoctorName
SelectedValue = DoctorName from the tblPatientsBIndingSource.

I'm not going to deal with the DataGridView thing at this point.
I'm just going to think about having the combobox on the screen,
and then you can put it in a DGV if you want to.

So the problem is the doctors that no longer work there.
When you display a patient that has one of those doctors, the
combobox goes blank.

I put together a test project, and found this to be true, which
didn't surprise me. If you are going to use data binding, it
won't show the non-current doctors because they are not in the
list you are using.

This is what I can't understand: if my combobox binds to
tblPatientsSource (in the 'Selected value' property) , it should
display *only* the values coming from the 'Patients' table, therefore
the 'old doctor' items only...
So now what do you do? Here's some ideas in descending order of
usefulness.

(1) Change the Doctor to a textbox and bind it and disable it
for input and put a label on it calling it "Last Doctor Seen".
Put a combobox next to it of the new and valid doctors and
call it "Current Doctor". If it doesn't display, they don't have one.

So you bind LastDoctorSeen to the DoctorName in the patients
table. You bind the CurrentDoctor the way you have it now.
When they select a CurrentDoctor, it should fill in the
LastDoctorSeen
to the same value.

The #1 solution is what I'm using now. It's an elegant way to skip
this issue. But, when I change the doctors from the combobox, the text
box doesn't update immediatly, I still see the 'old doctor name' until
I click to the Save icon on the bindingnavigator...
(2) Change the Doctor to a textbox and bind it and disable it
for input. Put a button next to it <Select Doctor> that shows
a form they can use to select a doctor.

(3) Add all the doctors to the dropdown list. There are a multitude
of ways to accomplish this: join the data tables, create a generic
list, etc.. Then if they try to change it, check and see if the
doctor is valid, and if it's not, don't let them save it until
they fix it.

Frankly, #1 seems like the best option, especially if you want
to make sure each patient has a valid current doctor.

I would have structured my tables differently, but maybe you don't
have control over that.

Good luck. Hope this helps.
Robin S.

Thanks Robin.
 

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