ListView selectindex event bug?????

H

HABJAN ®iga

Ok, the trouble:

On form:

Mask (lots of textboxes & ...)
Listview 1 as Listview with some items
booEdit as boolean=False
intEditIndex as integer

Scenario:
- i select item 1
(i get event Listview1.SelectIndexChanged - i load the mask for
selected item)
- i go to edit mode of the mask for selected item (i set booEdit=true,
intEditIndex = Listview1.selecteditems.item(0).index)
- i change some fields on my mask
- then i click on other item10 (i get event
Listview1.SelectIndexChanged), and i ask myself in event if i'am in edit
mode then ask me to save changes...
- res = msgbox("Do you want to save changes?",yesnocancel,...)
case Yes: i save the mask (for item1) and let listview1 go to item10
(...load the mask....booEdit=false....)
case No: same as yes, but no saving the changes
case Cancel (the trouble): i do nothing except i want that item1 is
selected.

Private Sub ListView1Ch(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Listview1.SelectedIndexChanged
If Listview1.selecteditems.count > 0 then
if me.editmode then
Dim res As Microsoft.VisualBasic.MsgBoxResult
res = MsgBox("Save?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Question)
if res = msgboxresult.cancel then
me.listview1.items(me.intEditIndex).selected=true;
end if
else
loadmask(listview1.selecteditems.item(0))
end if
end if
End Sub

I understand that when i call
'me.listview1.items(me.intEditIndex).selected=true;' i will be notifyed
again on event Listview1.SelectedIndexChanged so i added another boolean to
filter out unwanted events (see the booSlave).

Dim booSlave as boolean=false
Private Sub ListView1Ch(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Listview1.SelectedIndexChanged
if booSlave=true then exit sub
If Listview1.selecteditems.count > 0 then
if me.editmode then
Dim res As Microsoft.VisualBasic.MsgBoxResult
res = MsgBox("Save?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Question)
if res = msgboxresult.cancel then
booSlave=true
me.listview1.items(me.intEditIndex).selected=true;
booSlave=false
end if
else
loadmask(listview1.selecteditems.item(0))
end if
end if
End Sub

The trouble is when i'am in debug mode (doing it step by step) everything
turns out ok, but when i do it in runtime (no breakpoints), i get the
messagebox asking me to save 2 times....

Bug or my mistake?
Thanks for taking interest in reading this.

re, HaBiX


(framework 1.1, vs 2003 EA, vb.net)
 
E

EricJ

are you sure the booSlave boolean stays true ?? i think you have to declare
it as private

eric
 
H

HABJAN ®iga

dim editmode as boolean (declared in form)

i like to use word "me." because it display members so i don't have to type
a lot :blush:)

habix
 
C

Cor

Hi Habjan,
I tried it and then messagebox shows only one time in release mode and in
debug mode.

I don't like that index change event , I use mouse down.

But you did all that humbug to prevent that it fires too often.

I could not find it and I saw you were using the same framework and VB as I.

Maybe someone else has the same problems as you with this code.

Cor
 
R

Rick Mogstad

you should be able to push ctrl+space and get the intellisense to work, once you start typing the
word.
 
E

EricJ

is it me or dous the ListView1.SelectedItems.Count give 0 even if the first
item is selected?

Dim i As Integer = ListView1.SelectedItems.Count

If i > 0 Then

If booEditMode = True Then



End If
 
C

Cor

Hi Eric,
Most indexes starts in VB.net at 0. Only the so called
Microsoft.Visual.Basic components are starting mostly at 1. (VB collection,
funtions like find etc).

I hope this helps a little bit?
Cor
 
H

HABJAN ®iga

When you have item1 selected and you click on other item you get 2 events:

- The first one is triggered when the first item is deselected
(multiselect)
- The second one notifys you the new item is selected


anyways thanks for all the help guys

best re,
habix
 

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