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)
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)