Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

listview with checkboxes!Urgent

218 views
Skip to first unread message

Srinivas Kotipalli

unread,
Jul 5, 2002, 11:51:19 PM7/5/02
to
Hi,

Somebody please help.
I have a listview with checkboxes option turned on. when I select multiple
items by clicking mouse button it is automatically turning on check boxes
for previous selected items. I do not want this behaviour (because when user
unselects a item the check box is not turned off).

how can I disable this behaviour, even if it means subclassing please let me
know if this is possible. I tried the following code.....

for i = 0 to listview1.items.count - 1
listview1.item(i).checked = listview1.item(i).selected
next

thank you!


VBDotNet Team [MS]

unread,
Jul 8, 2002, 4:20:32 PM7/8/02
to
The following code both selects and checks a single item, and unchecks all
other items in a ListView with a single click. If you want to select
mulitple items, hold down the Ctrl key with each click.
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

Dim i As Integer

For i = 0 To ListView1.Items.Count - 1

ListView1.Items(i).Checked = ListView1.Items(i).Selected

Next

End Sub


Does this answer your question?

Dan Morseburg and Baiju (VB)

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

"Srinivas Kotipalli" <srin...@sbcglobal.net> wrote in message
news:uZsxXBKJCHA.2320@tkmsftngp11...

Srinivas Kotipalli

unread,
Jul 8, 2002, 11:52:59 PM7/8/02
to
Thanks for the reply. But it does not answer my question. I tried this code
and lot of other ways to change the default behaviour of the control, but
couldn't achieve what i wanted to. here is the detail description.

1. I have a list view - with CheckBoxes and 'FullRowSelect' and also
'Multiselect' turned on.
2. Now when I multiselect the items, by holding down shift button and mouse
click, all the "****previous*****" items get selected. So far so good. But
if we unselect it or change the selection mode, by clicking the mouse
somewhere else, it does not get unchecked.
3. First of all, I do not know why the check box is getting checked when I
do multiselect. I tried the code as I explained in the previous post and lot
of other ways like 'ItemCheck' event etc., etc., to change this behaviour.

Please let me know if you need further details. Thanks for any help and
advice, I do not want to buy a third party tool for this. So far in this
application we are not using any third party control.

Only two things may force us go that route. The listview does not allow
Wrapper text in column headers, and this (mis)behaviour of Checkboxes. Any
help will be much appreciated.

Thank you!


"VBDotNet Team [MS]" <vbdo...@microsoft.com> wrote in message
news:uelJMzrJCHA.1636@tkmsftngp10...

VBDotNet Team [MS]

unread,
Jul 9, 2002, 4:11:00 PM7/9/02
to
I'm afraid that we don't understand the question because we are confused by
the two states: selected and checked. You have a Windows Form in VB .NET
with a Windows Forms ListView control, right? In Properties,
CheckBoxex=True, MultiSelect=True, FullRowSelect=True.

By default if you single-click any item it becomes selected, but not
checked. If you shift+click items, they become multi-selected but not
checked. If you double-click a single item, it becomes selected and
checked, and all previously checked items remain checked. Let's say you
have items A, B, C, D, E, F in the ListView. If you add the code sample
below to the SelectedIndexChanged event, click A, then Shift+double-click D,
items A, B, C & D will be both selected and checked. To select and check
additional items use Ctrl+click.

If you have no code in your SelectedIndexChanged event then clicking and
shift+clicking will select, but not check the items. We're not sure which
behavior you want to change, the fact that the items become de-selected, or
unchecked, or both? What real-world situation are you trying to solve?

Dan Morseburg and Baiju (VB)

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

"Srinivas Kotipalli" <srin...@sbcglobal.net> wrote in message

news:uuP2IwvJCHA.2320@tkmsftngp11...

Srinivas Kotipalli

unread,
Jul 9, 2002, 11:06:45 PM7/9/02
to
Hi,
First of all Let me thank you, for trying to be patient with me and my
problem. I really appreciate that. Well here is my problem again.

Everything is like you explained in the first paragraph. And let us assume I
have five items in my listview viz., A,B,C,D,E and F. And I have no code in
the SelectedIndexChanged event.

1. If I shift+click item A. Item gets selected and not checked.
2. Now shift+Click item B. Item A gets checked.
3. Now just click on item B. Item A which got checked due to previous action
(step 2) does not get unchecked.

do you see the same behaviour or is it something to do with my settings or
am I doing something wrong.

The business behind the problem is:
Use has an option to select multiple items in the listview. As he selects
the items a running total of the selected items is calculated
(selectedindexchanged event is used). If he is satisfied with the total he
will then check all the selected items and do some process with the checked
items.


My problem is with step 2. If I shift+click multiple items, except for the
current item all other items get selected as well checked. Am I clear now?

Please let me know.
thank you!


"VBDotNet Team [MS]" <vbdo...@microsoft.com> wrote in message

news:eR5XhS4JCHA.1620@tkmsftngp10...

VBDotNet Team [MS]

unread,
Jul 10, 2002, 3:53:36 PM7/10/02
to
We think we understand the behavior you are seeing. We followed the three
steps you listed below. We are not seeing the same behavior. When we
shift+Click item B, A remains selected, and B is now selected. Neither of
them are checked. We don't see any properties of the ListView control that
would give you this behavior. Make sure you have no code that changes the
Selected or the Checked state of the ListView. You might have code in
another event handler that is changing the state. You should try to create
a new, empty VB Windows Application, drag a ListView control to the default
form, and see if the same behavior reproduces.

If the user just wants to check all items that have been selected, you could
add a button to the form which will check all selected items in the
ListView. Put the following code in the event handler for the button click:

Dim myItem As ListViewItem

' Uncheck all checked items

For Each myItem In ListView1.CheckedItems

myItem.Checked = False

Next

' Check currently selected items

For Each myItem In ListView1.SelectedItems

myItem.Checked = True

Next

Dan Morseburg & Baiju (VB)

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

"Srinivas Kotipalli" <srin...@sbcglobal.net> wrote in message

news:OE#c$67JCHA.2404@tkmsftngp11...

VBDotNet Team [MS]

unread,
Jul 11, 2002, 4:00:23 PM7/11/02
to
We were able to reproduce the behavior you are seeing. It helped to know
that you had multiple columns. There is nothing wrong with your code. We
tried a few work-arounds in the SelectedIndexChanged event handler, but none
would give you the behavior you desire. We suggest that you set
FullRowSelect to False. It is not the best solution, but it should prevent
the unexpected check and uncheck behavior.

Thanks for bringing this issue to our attention. We will report the behavior
to our development team.

Dan & Baiju (VB)

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


"Srinivas Kotipalli" <srin...@sbcglobal.net> wrote in message

news:el8j5mHKCHA.1900@tkmsftngp11...
> Hi Dan & Baiju ,
>
> Okay, As suggested by you I created the new application and the behaviour
is
> same for me. I am also attaching the code. One thing I noticed is....
>
> 1. Check boxes are always attached to the first column in the list view.
> 2. If you multiselect items by shift+ click on the first column - the
items
> do not get checked.
> 3. But when I shift + click on any column other than first - the items get
> checked like I posted.
>
> When it is full row select - user may click anywhere on the item (I mean
on
> any column!). Hope you will agree with me now?
> thank you,
> Srinivas


>
> "VBDotNet Team [MS]" <vbdo...@microsoft.com> wrote in message

> news:Or5RdtEKCHA.1356@tkmsftngp10...

Srinivas Kotipalli

unread,
Jul 11, 2002, 9:24:31 PM7/11/02
to
Thank You!

"VBDotNet Team [MS]" <vbdo...@microsoft.com> wrote in message

news:##WrAWRKCHA.2156@tkmsftngp10...

dah...@googlemail.com

unread,
Jul 26, 2013, 11:28:30 AM7/26/13
to
That workaround worked for me, but its C#.

I noticed, that the value for the Checkbox is still valid at this point,
so I decided to "reset" the values when there is a multi selection.
Just add the event ItemCheck of the ListView to your code....

private void YourListView_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (listview_fields.SelectedItems.Count > 1) e.NewValue = e.CurrentValue;
}

dah...@googlemail.com

unread,
Jul 26, 2013, 11:29:53 AM7/26/13
to
Am Freitag, 26. Juli 2013 17:28:30 UTC+2 schrieb dah...@googlemail.com:
> That workaround worked for me, but its C#.
>
>
>
> I noticed, that the value for the Checkbox is still valid at this point,
>
> so I decided to "reset" the values when there is a multi selection.
>
> Just add the event ItemCheck of the ListView to your code....
>
>
>
> private void YourListView_ItemCheck(object sender, ItemCheckEventArgs e)
>
> {
>
> if (YourListView.SelectedItems.Count > 1) e.NewValue = e.CurrentValue;
>
> }
0 new messages