473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Cancelling a user change in a combo box

I have a combobox control on the form. When the user makes a change, I want
to validate a condition before permitting the change. If the condition is
not met, I want to return the ComboBox text back to its previous value. He
is what I tried.

(1) Validating event does not work because user is not exiting the control.
(2) My condition testing code is in the SelectedIndexChanged event.
Unfortunately I can't find a way to recover the previous value if test fails.
(3) There is no .....changing event that I can use that supports e.cancel =
True. (4) My best thought is to set a class variable in the mouseDown event
to capture the current value and use that class variable in the
SelectedIndexChanged event if the condition test fails.

One would think there is an easier way than my #4 method but I can't find
it. Any alternative approach to this problem will be appreciated.
Nov 21 '05 #1
4 6993
If a selection is invalid, why present it to the user?
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
I have a combobox control on the form. When the user makes a change, I
want
to validate a condition before permitting the change. If the condition is
not met, I want to return the ComboBox text back to its previous value.
He
is what I tried.

(1) Validating event does not work because user is not exiting the
control.
(2) My condition testing code is in the SelectedIndexChanged event.
Unfortunately I can't find a way to recover the previous value if test
fails.
(3) There is no .....changing event that I can use that supports e.cancel
=
True. (4) My best thought is to set a class variable in the mouseDown
event
to capture the current value and use that class variable in the
SelectedIndexChanged event if the condition test fails.

One would think there is an easier way than my #4 method but I can't find
it. Any alternative approach to this problem will be appreciated.

Nov 21 '05 #2
More specifics on the problem. My combobox contains a list of topics that
can be edited in an RichTextBox. If a person does not edit the topic, I want
the combobox to show a new topic from the list. If the user edits the topic,
I want to verify that the user saved the topic before changing to a different
topic.

In my question the test condition referred to whether the previous topic was
saved, not a question of a selection being invalid.

"JohnFol" wrote:
If a selection is invalid, why present it to the user?
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
I have a combobox control on the form. When the user makes a change, I
want
to validate a condition before permitting the change. If the condition is
not met, I want to return the ComboBox text back to its previous value.
He
is what I tried.

(1) Validating event does not work because user is not exiting the
control.
(2) My condition testing code is in the SelectedIndexChanged event.
Unfortunately I can't find a way to recover the previous value if test
fails.
(3) There is no .....changing event that I can use that supports e.cancel
=
True. (4) My best thought is to set a class variable in the mouseDown
event
to capture the current value and use that class variable in the
SelectedIndexChanged event if the condition test fails.

One would think there is an easier way than my #4 method but I can't find
it. Any alternative approach to this problem will be appreciated.


Nov 21 '05 #3
Genojoe,

I am not sure if I understand you, however a static variable in the index
change event seems for me the most on what you are asking.

\\\
Private sub selectedindexchange...............
static mysaver as string
'do all the stuff

mysaver = combo.text
end sub
///

I hope this helps,

Cor
Nov 21 '05 #4
Thank you. The single word "Static" solved the problem. Here is the
abridged code that I developed using a static variable. Note that I am using
the bSkipCode variable to keep this procedure out of an endless loop.

As an aside, if anyone reads this topic and has a better way to stop an
endless loop, I would love to learn about it. I frequently run into the
problem with needing to stop such a loop. Is using a static variable this
way the best way to do it. I am always looking for the cleanest way to solve
a problem.

Private Sub cboUser_SelectedIndexChanged(...........
Static iIndex As Integer
Static bSkipCode As Boolean
If bSkipCode = True Then
bSkipCode = False
Exit Sub
End If
If priTestForDirty(rtfUser) Then
MsgBox("Topic is not saved. You cannot move to another topic.")
bSkipCode = True
cboUser.SelectedIndex = iIndex
Else
iIndex = cboUser.SelectedIndex
End If
End Sub
"Cor Ligthert" wrote:
Genojoe,

I am not sure if I understand you, however a static variable in the index
change event seems for me the most on what you are asking.


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message...
5
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still...
1
by: Ajab Gajab | last post by:
Hi All, I am developing an application in VB.Net where I need to provide user with cancelling or stopping the current print job. Like, if a user clicks on "stop" button, then printer should print...
2
by: G .Net | last post by:
Hi Is there a way to prevent the combo displaying its list of items when the "combo arrow" is clicked? The problem I'm trying to resolve is that depending on a Boolean value, which is set...
3
by: hary08 | last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and...
2
by: Mark Anderson | last post by:
Is it possible to identify the action of a user cancelling by the user of file download dialog? (as opposed to something else being captured. Ideally I'd like to do this for a IE6+/FF v1.5+/Safari...
2
by: giannis | last post by:
Is possible to cancel completely the PgDown behavior at a combo box (Simple,Suggest)?
1
by: commodityintelligence | last post by:
Greetings, I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming...
2
by: ruthie | last post by:
Hi, I have a gridview with edit option. If the user chooses to edit the row and then press the Cancel button - I would like the focus to return to the chosen row. Someone has any idea how to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.