473,396 Members | 1,836 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,396 software developers and data experts.

Deny move within a listbox?

I'm looking for a way to deny a move from the current listbox item. For
instance, if the user is editing the record associated with the current
listbox item I want to deny a move within the listbox until they have saved
the changes. Is there any way to deny a move from the current item so the
SelectedIndexChanged event never fires no matter move the movement was
attempted? Whether the user uses the cursor keys or mouse to try and leave
the current item I want to be able to block the movement until certain
conditions are met. I suppose I could allow the move, check a condition and
send them back to the previous item if necessary, but I would rather prevent
the departure from the current item in the first place.
Nov 15 '05 #1
7 2026

Hi Byron,

Thank you for posting in the community!

Is your application WebForm based or WinForm based?

And, if your application is WinForm based, you use ListBox control or
ListView control on your form? Only ListView control has the item edit
function, ListBox has no item edit function.

If you was still use the ListBox, can you show me the code how you edit the
listbox item ?

Please provide me the information, so that we can help you better, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
It's a WinForm based application using a ListBox control. The control
serves as a list of items that may be edited and as the user selects items
in the list edit fields are populated with the details of the currenty
selected item. I am not trying to edit within the list, but I want to
prevent the user from moving to another item until I decide they can,
normally preventing the movement because they have not saved changes to the
current item.
"""Jeffrey Tan[MSFT]""" <v-*****@online.microsoft.com> wrote in message
news:0U*************@cpmsftngxa06.phx.gbl...

Hi Byron,

Thank you for posting in the community!

Is your application WebForm based or WinForm based?

And, if your application is WinForm based, you use ListBox control or
ListView control on your form? Only ListView control has the item edit
function, ListBox has no item edit function.

If you was still use the ListBox, can you show me the code how you edit the listbox item ?

Please provide me the information, so that we can help you better, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3

Hi Byron,

Thanks very much for your feedback.

Ok, I see your concern: you want to disable the item selection in ListBox
control when certain item is editing.

I think you can extend the ListBox control, override WndProc method, then
filter the WM_KEYDOWN and WM_LBUTTONDOWN message.
Do like this:

// The code in the extendedListBox
public bool disable=false;
protected override void WndProc(ref Message m)
{
if(disable==true)
{
if(m.Msg==WM_KEYDOWN)
{
return;
}

if(m.Msg==WM_LBUTTONDOWN)
{
return;
}
}
base.WndProc (ref m);
}

// The code in the test form
private void button1_Click(object sender, System.EventArgs e)
{
extlistbox1.disable=true;
}

private void button2_Click(object sender, System.EventArgs e)
{
extlistbox1.disable=false;
}

In the code, extlistbox1 is an instance of extendedListBox. In the test
form, I disable and enable the "disable" variable in 2 Button.Click event.

=============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4
Hi Byron,

Does my solution resolve your issue?

If you still have anything unclear, please feel free to post, I will help
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5
I was actually trying to head in a different direction.

I want to leave the list enabled no matter what the current mode is.
Basically I allow all users to browse records in a view-only mode. As they
navigate the listbox the details of the current record are displayed in a
richtext box. If the user has the correct permissions the can select Edit
and the richtext is hidden, edit fields appear populated for editing, and I
set a Boolean IsEditing = true. From this point if the user attempts to
navigate away from the current record, close the form, or close the
application the current record is checked to see if they have changed it.
If they have changed it, they are prompted to Save, Abandon changes, or
Cancel to return to the current record for further editing. If they choose
Cancel, or the save fails, they are returned to the record for further
editing.

This means I have to reposition within the listbox to the one they were on
when they attempted to leave it. What I was hoping for is the ability to
something similar to the Cancel on a form closure to automatically return to
the listbox item it was on prior to the move. I assume though that I will
have to do it programmatically to reposition based on the item index or the
Value property within the list of objects in the listbox.
"""Jeffrey Tan[MSFT]""" <v-*****@online.microsoft.com> wrote in message
news:Qd**************@cpmsftngxa06.phx.gbl...
Hi Byron,

Does my solution resolve your issue?

If you still have anything unclear, please feel free to post, I will help
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6
Hi Byron,

Thanks very much for your feedback.

Oh, I think the expression in your reply is just the whole program logic of
your application. In your logic, there are many steps. I think most of the
steps you have fulfilled successfully. Can you show me which step is your
main concern and key obstacle? Then I will help you solve this obstacle.

In your second paragraph, "This means I have to reposition within the
listbox to the one they were on when they attempted to leave it", what does
the last word "it" mean?
There are 2 understandings:
1). "it" means TextBox that is for editing current record.
I think you should refer to TextBox's Validating event, then when your
focus is leaving the TextBox, this event gives you a chance to do something

2). "it" means the currect editing listitem
I think my original reply solution just shows you how to deny move in a
listbox.

If I misunderstand you, please feel free to correct me, and explain more
details to me, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #7
By "it" I mean the item currently being edited, not any particular field. I
am currently using the SelectedIndexChanged event to retrieve the record the
user selected in the listbox from the database for display and/or editing.
I just want to stop the new record from being loaded and return to the old
one if the old one has pending edits not committed to the database. If the
application recognizes the current record is dirty the user is offered the
chance to save the record and continue on to the one they selected within
the list, abandon the changes to the old record and continue to the record
they selected, or cancel the move and return to editing the previous record.
"""Jeffrey Tan[MSFT]""" <v-*****@online.microsoft.com> wrote in message
news:gO**************@cpmsftngxa06.phx.gbl...
Hi Byron,

Thanks very much for your feedback.

Oh, I think the expression in your reply is just the whole program logic of your application. In your logic, there are many steps. I think most of the
steps you have fulfilled successfully. Can you show me which step is your
main concern and key obstacle? Then I will help you solve this obstacle.

In your second paragraph, "This means I have to reposition within the
listbox to the one they were on when they attempted to leave it", what does the last word "it" mean?
There are 2 understandings:
1). "it" means TextBox that is for editing current record.
I think you should refer to TextBox's Validating event, then when your
focus is leaving the TextBox, this event gives you a chance to do something
2). "it" means the currect editing listitem
I think my original reply solution just shows you how to deny move in a
listbox.

If I misunderstand you, please feel free to correct me, and explain more
details to me, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #8

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

Similar topics

7
by: Carlos Marangon | last post by:
hello! Can anyone please tell me where can I find a script that deny access if password is wrong 3 times CM
1
by: Job Lot | last post by:
I have worked out how to move items in ListBox when it is populated using Items collection, but it doesn't seems to work when the ListBox is bound to a DataSource. How can i move items when...
4
by: Alienz | last post by:
I have a subform where I have a subform with 20 options to select from. When I set the multiselect property to simple and select multiple options, nothing is stored. I have another table with...
1
by: kent | last post by:
Hi All, On my form, I have 2 listboxes that get populated with the correct items. I have 4 buttons between the 2 boxes. The first 2 buttons are used to move the selected item back and forth...
5
by: Powerguy | last post by:
Hi, I am trying to allow users to only be able to enter numeric numbers into a textbox. The problem is that I cannot move focus with the tab key even if I allow it as an allowable key stroke. I...
1
by: anjupt | last post by:
Hi, I have 2 listboxes with data fetched from database so for both the listboxes datasource is set .i tried to move data from one listbox to another listbox but Error"An unhandled exception of...
6
patjones
by: patjones | last post by:
Sometimes you might have two list boxes side by side, and want to double-click on an item in one box to move it to the other. For instance, maybe the first list box contains a list of customers,...
4
by: mikkoO8 | last post by:
hi. im actually making a desktop cleaner that can move the files and icons to a folder inside the listview box. i can make the listview box filled with files contains at the desktop and i can make...
4
by: bogdan | last post by:
Hi, I have two listboxes on a page and need to move items between them - using buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net? I'd like to avoid hitting the server on...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.