By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,680 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,680 IT Pros & Developers. It's quick & easy.

ListView selectindex event bug?????

P: n/a
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)
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
are you sure the booSlave boolean stays true ?? i think you have to declare
it as private

eric

"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
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)

Nov 20 '05 #2

P: n/a
Cor
Hi HABJAN,
if me.editmode then


What is that, I did not see it as a member of the form, but maybe I see
something wrong?

Cor
Nov 20 '05 #3

P: n/a
OK... if someone want's to try it get the source code from
http://www.intelcom.si/test.zip

Click on item1 (select it)
Click on edit
Then click on item 3

best re, habix
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
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)

Nov 20 '05 #4

P: n/a
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 :o)

habix

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi HABJAN,
if me.editmode then


What is that, I did not see it as a member of the form, but maybe I see
something wrong?

Cor

Nov 20 '05 #5

P: n/a
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
Nov 20 '05 #6

P: n/a
you should be able to push ctrl+space and get the intellisense to work, once you start typing the
word.
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message news:bm********@enews3.newsguy.com...
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 :o)

habix

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi HABJAN,
if me.editmode then


What is that, I did not see it as a member of the form, but maybe I see
something wrong?

Cor


Nov 20 '05 #7

P: n/a
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
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
OK... if someone want's to try it get the source code from
http://www.intelcom.si/test.zip

Click on item1 (select it)
Click on edit
Then click on item 3

best re, habix
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
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)


Nov 20 '05 #8

P: n/a
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
Nov 20 '05 #9

P: n/a
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

"EricJ" <er********@THISomnipack.be> wrote in message
news:3f***********************@reader1.news.skynet .be...
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
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
OK... if someone want's to try it get the source code from
http://www.intelcom.si/test.zip

Click on item1 (select it)
Click on edit
Then click on item 3

best re, habix
"HABJAN 展ga" <habix[AT]intelcom[DOT]si> wrote in message
news:bm********@enews3.newsguy.com...
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)



Nov 20 '05 #10

P: n/a
Cor
Hi Habjan,
That is why I told you I use the mouse down
Cor
Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.