Checking CheckBoxes of ListView at runtime

  • Thread starter Thread starter boble
  • Start date Start date
B

boble

I would like to change the CheckBoxes property of a list
view at runtime, but doing so does not show the checkboxes.
The text in the first column is aligned to the right side
and you have to click several times on an empty space (of
the column) in order to have the checkbox show up.

Anyone know a fix to this?

Thanx all!

PS: I use listView.Invalidate(true) when CheckBoxes
property is set to true.
 
Hi Bob,

Can you provide more detail on the following questions? I tried this a few
different ways and was not able to see the behavior you're describing.

1. What framework version are you using (1.0 or 1.1)?
2. What version of VS.NET are you using?
3. Besides changing the CheckBoxes property of the ListView, what other
properties were changed? Specifically, what is your View property set to?

What I did is created a default windows application and added a ListView
control to the form. Then, I added a couple of columns and made the first
column right justified. Next, I added some items using the ListViewItem
Collection Editor. Finally, I added a button that when clicked, simply
toggles the CheckBoxes property of the ListView. I tested this on version
1.1 of the framework using VS.NET 2003.

Thanks,
Rick [MSFT]

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
| I would like to change the CheckBoxes property of a list
| view at runtime, but doing so does not show the checkboxes.
| The text in the first column is aligned to the right side
| and you have to click several times on an empty space (of
| the column) in order to have the checkbox show up.
|
| Anyone know a fix to this?
|
| Thanx all!
|
| PS: I use listView.Invalidate(true) when CheckBoxes
| property is set to true.
|
 
Hello Rick:

thank you for your reply and sorry for my delay ...

I tried to create a small piece of code that would show
better what the problem was but couldnt do it.

It is very hard to pinpoint where the problem is cuz
several .NET classes have been derived from, such as:

- XItem class derives from ListViewItem;
- XList class derives from ListView;
- XYList class derives from XList; (borth XList and XYList
have two columns)


Now, I was trying to change the CheckBoxes property of
XYList at runtime and it the checkboxes would fail to
show. The items can be added/removed at runtime. The label
of the first column (where a checkbox were to show) would
be right-aligned and one would have to double-click on the
cell to have the checkbox show up.

The workaround? I found the following to work:

bool existing = listView.CheckBoxes;
listView.CheckBoxes = true;
listView.Items.Add(new XItem(cust-obj));
listView.CheckBoxes = existing;


Im using Visual Studio 7.1.3088, .NET Framework 1.1.4322
on Windows 2000 professional with Service Pack 4.

My View property is set to Details.

Thanx,
 
Hi Bob,

The code you listed as a "work-around" for you is exactly the same thing I
was doing before. I also confirmed that we're running the same version.
I'm glad you found a way to solve your problem, but I'm concerned that
there is an issue that remains unsolved.

One thing I noticed is that the first column of the listview is always left
aligned. You indicated before that your first column was right aligned.
This conflicts with the sample I tried. I can align second and subsequent
columns to center or right, but the first column is always left aligned. I
tried adjusting the alignment of the first column at runtime also, but it
just ignores the alignment. So, I'm not clear on how you were aligning the
first column to the right. Do you have the code that was faulting before?
If so, what is different about it than what you have listed as code that
works for you?

Either way, I tried a few more scenarios and was not able to observe the
behavior.

Thanks,
Rick [MSFT]

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
| Hello Rick:
|
| thank you for your reply and sorry for my delay ...
|
| I tried to create a small piece of code that would show
| better what the problem was but couldnt do it.
|
| It is very hard to pinpoint where the problem is cuz
| several .NET classes have been derived from, such as:
|
| - XItem class derives from ListViewItem;
| - XList class derives from ListView;
| - XYList class derives from XList; (borth XList and XYList
| have two columns)
|
|
| Now, I was trying to change the CheckBoxes property of
| XYList at runtime and it the checkboxes would fail to
| show. The items can be added/removed at runtime. The label
| of the first column (where a checkbox were to show) would
| be right-aligned and one would have to double-click on the
| cell to have the checkbox show up.
|
| The workaround? I found the following to work:
|
| bool existing = listView.CheckBoxes;
| listView.CheckBoxes = true;
| listView.Items.Add(new XItem(cust-obj));
| listView.CheckBoxes = existing;
|
|
| Im using Visual Studio 7.1.3088, .NET Framework 1.1.4322
| on Windows 2000 professional with Service Pack 4.
|
| My View property is set to Details.
|
| Thanx,
|
| >-----Original Message-----
| >Hi Bob,
| >
| >Can you provide more detail on the following questions?
| I tried this a few
| >different ways and was not able to see the behavior
| you're describing.
| >
| >1. What framework version are you using (1.0 or 1.1)?
| >2. What version of VS.NET are you using?
| >3. Besides changing the CheckBoxes property of the
| ListView, what other
| >properties were changed? Specifically, what is your View
| property set to?
| >
| >What I did is created a default windows application and
| added a ListView
| >control to the form. Then, I added a couple of columns
| and made the first
| >column right justified. Next, I added some items using
| the ListViewItem
| >Collection Editor. Finally, I added a button that when
| clicked, simply
| >toggles the CheckBoxes property of the ListView. I
| tested this on version
| >1.1 of the framework using VS.NET 2003.
| >
| >Thanks,
| >Rick [MSFT]
| >
| >This posting is provided "AS IS", with no warranties, and
| confers no rights.
| >
| >--------------------
| >| I would like to change the CheckBoxes property of a
| list
| >| view at runtime, but doing so does not show the
| checkboxes.
| >| The text in the first column is aligned to the right
| side
| >| and you have to click several times on an empty space
| (of
| >| the column) in order to have the checkbox show up.
| >|
| >| Anyone know a fix to this?
| >|
| >| Thanx all!
| >|
| >| PS: I use listView.Invalidate(true) when CheckBoxes
| >| property is set to true.
| >|
| >
| >.
| >
|
 
Back
Top