Combo Box not Repainting when updated out of focus

C

cms0007

I am using C# on a windows form with three tabs. Each tab holds a user
control and there are several combo boxes on each user control. On all
three user controls there is a combo box that contains information from
the same location in a database. but the information is displayed
differently in each instance. In one combo box all values from the
table are displayed, on another box only the values that meet a certain
criteria are displayed and on the third combo box only the values that
meet an additional criteria are displayed so all three display
different information from the same source. On one of the controls I
can update the information in the DB. When I do so I want the other
combo boxes on the other user controls to update their information,
essentially requery the database and redisplay the new information.
This works fine for the combo box that is on the user control in focus
but the user controls on the other two tabs that were not in focus when
there combobox data was updated seem to lose the ability to repaint
themselves. However they do seem to have the updated information. I
can click where the drop down arrow is though I cannot see the drop
down arrow. The combo box will drop down and show the values inside
though the text box portion will not repaint. I can scroll through the
list of values in the dropdown though I cannot see the combo box
scrolling and I can select a value, though I cannot see the value I
scrolled to. The combo boxes that were out of focus when their data
was updated will not repaint until I close and reopen the form. I also
tried a different method of throwing an event on the user control in
focus that told the parent form that the combo boxes need to be
updated. The parent form in turn would notify the other user controls
that they needed to update their combo boxes by setting a variable and
then on the Enter event on the other user controls I checked the
variable to see if it was true when the user control comes into focus
and if so would requery the info in the database and refill the combo
box but this did not work either. The combo box will not repaint it
self even though its info if updated when the combo is in focus it
appears.

It seems this has something to do with the idea that you should not
update the UI directly from a worker thread but should call the UI's
Invoke method for updating which I tried doing as well but it does not
seem to work either.
 
J

Jeff Gaines

It seems this has something to do with the idea that you should not
update the UI directly from a worker thread but should call the UI's
Invoke method for updating which I tried doing as well but it does not
seem to work either.

I would suspect the Tab Control. Only the currently selected Tab Page gets
painted - if I understand how it works all the controls on an unselected
Tab Page are re-positioned to a large negative location thus effectively
removing them from the form until you click that page when they are
re-positioned to their proper locations.

Can you test it by temporarily placing the 3 x Combo Box on the same Tab
Page and see if that works? Might help to pin the problem down.
 
C

cms0007

Jeff said:
I would suspect the Tab Control. Only the currently selected Tab Page gets
painted - if I understand how it works all the controls on an unselected
Tab Page are re-positioned to a large negative location thus effectively
removing them from the form until you click that page when they are
re-positioned to their proper locations.

Can you test it by temporarily placing the 3 x Combo Box on the same Tab
Page and see if that works? Might help to pin the problem down.

Well I did it a little different. I just refilled the combo box while
on the same user control in focus using a button click and now it will
not repaint so it is unrelated to it being out of focus. However, it
is still a problem. I have about 15 other combo boxes that seem to
work fine when I refill then but these 2 lose their ability to repaint
themselves when they are refilled.
 
C

cms0007

Well I did it a little different. I just refilled the combo box while
on the same user control in focus using a button click and now it will
not repaint so it is unrelated to it being out of focus. However, it
is still a problem. I have about 15 other combo boxes that seem to
work fine when I refill then but these 2 lose their ability to repaint
themselves when they are refilled.

Not sure how many times I have run into this but it is certainly not
the first time. I just deleted the combo box and readadded it and now
it works fine. Pretty irritating to have wasted a day on that.
 

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