Home All Groups Group Topic Archive Search About

VB.NET ComboBox _SelectedIndexChanged

Author
12 Jul 2006 6:45 PM
MachuPicchu
Hi, I'm refreshing a panel based on a selection from a winforms combobox.
In my _SelectedIndexChanged event for the combobox, if changes to the
panel's controls are present I am checking the response from a messagebox to
proceed using MsgBoxStyle.YesNoCancel.

When clicking cancel on the messagebox, is there a way to have the combobox
rejected the changed index and revert back to the previous selection without
setting the selectedItem? Currently getting circular references when doing
that.

Code:

Private Sub cboPage_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboPage.SelectedIndexChanged
    If Not CInt(sender.SelectedItem.Value) <> _currentSetMax Then

        If ItemsModified Then

            Select Case MsgBox("Changes have been made, Save changes?",
MsgBoxStyle.YesNoCancel, "Items Changed")
                Case MsgBoxResult.Yes
                ' TO DO: Save the existing controls in the panel
                Case MsgBoxResult.Cancel
                'TO DO: Reset the cboPage to the previous selection and return
                Return
            End Select

        End If  
        ' TO DO: Refresh the controls in the panel

    End If

End Sub

Thanks!



--
..NET wannabe

Author
12 Jul 2006 7:29 PM
vbnetdev
I would store the current setting in a variable or xml document and if the
change was rejected set the previous entry as currently selected item
(index)

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



Show quoteHide quote
"MachuPicchu" <MachuPic***@discussions.microsoft.com> wrote in message
news:E11D1919-E039-435E-AD27-5E76F0AC16DA@microsoft.com...
> Hi, I'm refreshing a panel based on a selection from a winforms combobox.
> In my _SelectedIndexChanged event for the combobox, if changes to the
> panel's controls are present I am checking the response from a messagebox
> to
> proceed using MsgBoxStyle.YesNoCancel.
>
> When clicking cancel on the messagebox, is there a way to have the
> combobox
> rejected the changed index and revert back to the previous selection
> without
> setting the selectedItem? Currently getting circular references when doing
> that.
>
> Code:
>
> Private Sub cboPage_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles cboPage.SelectedIndexChanged
> If Not CInt(sender.SelectedItem.Value) <> _currentSetMax Then
>
> If ItemsModified Then
>
>     Select Case MsgBox("Changes have been made, Save changes?",
> MsgBoxStyle.YesNoCancel, "Items Changed")
>         Case MsgBoxResult.Yes
> ' TO DO: Save the existing controls in the panel
>         Case MsgBoxResult.Cancel
> 'TO DO: Reset the cboPage to the previous selection and return
> Return
>     End Select
>
> End If
> ' TO DO: Refresh the controls in the panel
>
> End If
>
> End Sub
>
> Thanks!
>
>
>
> --
> .NET wannabe
>
Author
12 Jul 2006 7:38 PM
Samuel Shulman
I never found a way, I believe that once this event is fired the index was
already changed

what you can do is to record to a static or class variable the index of the
selected item (After you approved the change) then if you don't like the
change you reset it to the previous recorded index
Then finally to avoid the method functionality you can Add a condition like
that

if ComboABC.SelectedIndex = iRecordedIndex then
    'Ignore and exit
Else
    'Perform the required functionality
    ......
End if


hth,
Samuel Shulman

Show quoteHide quote
"MachuPicchu" <MachuPic***@discussions.microsoft.com> wrote in message
news:E11D1919-E039-435E-AD27-5E76F0AC16DA@microsoft.com...
> Hi, I'm refreshing a panel based on a selection from a winforms combobox.
> In my _SelectedIndexChanged event for the combobox, if changes to the
> panel's controls are present I am checking the response from a messagebox
> to
> proceed using MsgBoxStyle.YesNoCancel.
>
> When clicking cancel on the messagebox, is there a way to have the
> combobox
> rejected the changed index and revert back to the previous selection
> without
> setting the selectedItem? Currently getting circular references when doing
> that.
>
> Code:
>
> Private Sub cboPage_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles cboPage.SelectedIndexChanged
> If Not CInt(sender.SelectedItem.Value) <> _currentSetMax Then
>
> If ItemsModified Then
>
>     Select Case MsgBox("Changes have been made, Save changes?",
> MsgBoxStyle.YesNoCancel, "Items Changed")
>         Case MsgBoxResult.Yes
> ' TO DO: Save the existing controls in the panel
>         Case MsgBoxResult.Cancel
> 'TO DO: Reset the cboPage to the previous selection and return
> Return
>     End Select
>
> End If
> ' TO DO: Refresh the controls in the panel
>
> End If
>
> End Sub
>
> Thanks!
>
>
>
> --
> .NET wannabe
>
Author
12 Jul 2006 8:58 PM
MachuPicchu
Thanks Samuel!
I knew there had to be a workaround.
Recalling my PowerBuilder days when what I described was possible and didn't
know if it could be handled in VB.Net as I described.

--
..NET developer
VS.NET 2005 Rocks!



Show quoteHide quote
"Samuel Shulman" wrote:

> I never found a way, I believe that once this event is fired the index was
> already changed
>
> what you can do is to record to a static or class variable the index of the
> selected item (After you approved the change) then if you don't like the
> change you reset it to the previous recorded index
> Then finally to avoid the method functionality you can Add a condition like
> that
>
> if ComboABC.SelectedIndex = iRecordedIndex then
>     'Ignore and exit
> Else
>     'Perform the required functionality
>     ......
> End if
>
>
> hth,
> Samuel Shulman
>
> "MachuPicchu" <MachuPic***@discussions.microsoft.com> wrote in message
> news:E11D1919-E039-435E-AD27-5E76F0AC16DA@microsoft.com...
> > Hi, I'm refreshing a panel based on a selection from a winforms combobox.
> > In my _SelectedIndexChanged event for the combobox, if changes to the
> > panel's controls are present I am checking the response from a messagebox
> > to
> > proceed using MsgBoxStyle.YesNoCancel.
> >
> > When clicking cancel on the messagebox, is there a way to have the
> > combobox
> > rejected the changed index and revert back to the previous selection
> > without
> > setting the selectedItem? Currently getting circular references when doing
> > that.
> >
> > Code:
> >
> > Private Sub cboPage_SelectedIndexChanged(ByVal sender As System.Object,
> > ByVal e As System.EventArgs) Handles cboPage.SelectedIndexChanged
> > If Not CInt(sender.SelectedItem.Value) <> _currentSetMax Then
> >
> > If ItemsModified Then
> >
> >     Select Case MsgBox("Changes have been made, Save changes?",
> > MsgBoxStyle.YesNoCancel, "Items Changed")
> >         Case MsgBoxResult.Yes
> > ' TO DO: Save the existing controls in the panel
> >         Case MsgBoxResult.Cancel
> > 'TO DO: Reset the cboPage to the previous selection and return
> > Return
> >     End Select
> >
> > End If
> > ' TO DO: Refresh the controls in the panel
> >
> > End If
> >
> > End Sub
> >
> > Thanks!
> >
> >
> >
> > --
> > .NET wannabe
> >
>
>
>