CheckedListBox and TabControl problem

S

Steve Cutting

Hi all,

I have a CheckedListBox on one pane of a TabControl on a form. I find that
whenever the user clicks a different tab then comes back, any checks that
were in the list have disappeared.

After a bit of experimenting I have discovered that the problem only occurs
when the CheckedListBox is using a dataset table as the source. If I
manually add items to it's collection using the properties window, it works
fine. If I bind it to a dataset table though, I get the checkbox clearing
problem.

In order to isolate the problem from the project I'm working on I did the
following:

1. Started a new project
2. Added a tab control with 2 tabs to the form
3. On one pane, added a CheckedListBox
4. Setup db-connection/data-adapter/dataset via the wizards
5. In the Form_load event put the following code:

DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11, "Products")

CheckedListBox1.DataSource = DataSet11
CheckedListBox1.ValueMember = "Products.ModelNo"
CheckedListBox1.DisplayMember = "Products.ModelNo"

6. Run

The form loads and the CheckedListBox is populated with the ModelNo fields
from my Products table as expected. Now I check a few lines. I then click
the other tab, and then click back to the original. The checks are gone.

Can anyone shed any light on this behaviour ??

I could just populate my CheckListBox manually, by reading my table with a
datareader and adding the lines one-by-one. I'm still curious as to how/if
the dataset approach can be made to work though.

thanks in advance

Steve
 
S

Steve Cutting

You're not alone.

Here is my posting about this problem from 2 years ago. Don't think I've
ever found a good solution.

http://tinyurl.com/557uy

I wonder if they fixed this in 2005?

Thanks Greg. I had wondered if it was just a bug, but assumed I was just
doing something wrong :p I am only just learning vb.net, and this sort of
thing doesn't exactly help matters.

I have already implemented a work-around for another CheckedListBox in my
form. For that one I'm able to restore the checks using data in my table, so
I just have a routine that runs on the indexchanged event of the tabcontrol.

For this CheckedListBox (ie the one I posted about) I think I will just
redesign my code and add the list items manually via a datareader, since I
have no way of restoring the checks without creating a temp array/collection
to store them.

thanks again
Steve
 
C

Cablewizard

WOW! I ran into this a long time ago and fought with it for a long time.
I ended up blaming Infragistics, as I was using some of their stuff as well.
After MUCH hair pulling, I "think" I narrowed it down to the Tab control as the
source of the problem.
I had other controls that had problems as well, that seemed to work just fine in
all other contexts.
I also experienced an issue where the presence of the tab control causes my Form
to resize at run time.
If I had things below the tab control, sometimes it would arbitrarily resize the
form to fit the bottom of the tab.
I have NO docking, NO resize code, NOTHING to affect the size of the form.

FWIW, I accidentally stumbled on something that works for me.
I really needed a multi-color checked list box with a custom right-click context
menu, so I created an inherited user control and overrode the OnDrawItem event.
When using my version of the control, I have not experienced this problem
anymore.

Gerald
 

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