• <legend id='cbRZY'><style id='cbRZY'><dir id='cbRZY'><q id='cbRZY'></q></dir></style></legend>
  • <tfoot id='cbRZY'></tfoot>
        <bdo id='cbRZY'></bdo><ul id='cbRZY'></ul>

    1. <i id='cbRZY'><tr id='cbRZY'><dt id='cbRZY'><q id='cbRZY'><span id='cbRZY'><b id='cbRZY'><form id='cbRZY'><ins id='cbRZY'></ins><ul id='cbRZY'></ul><sub id='cbRZY'></sub></form><legend id='cbRZY'></legend><bdo id='cbRZY'><pre id='cbRZY'><center id='cbRZY'></center></pre></bdo></b><th id='cbRZY'></th></span></q></dt></tr></i><div id='cbRZY'><tfoot id='cbRZY'></tfoot><dl id='cbRZY'><fieldset id='cbRZY'></fieldset></dl></div>

        <small id='cbRZY'></small><noframes id='cbRZY'>

      1. 取消 ListBox SelectedIndexChange 事件

        Cancelling ListBox SelectedIndexChange Event(取消 ListBox SelectedIndexChange 事件)
        <legend id='ywMCm'><style id='ywMCm'><dir id='ywMCm'><q id='ywMCm'></q></dir></style></legend>
        • <tfoot id='ywMCm'></tfoot>

            <small id='ywMCm'></small><noframes id='ywMCm'>

              <bdo id='ywMCm'></bdo><ul id='ywMCm'></ul>

                • <i id='ywMCm'><tr id='ywMCm'><dt id='ywMCm'><q id='ywMCm'><span id='ywMCm'><b id='ywMCm'><form id='ywMCm'><ins id='ywMCm'></ins><ul id='ywMCm'></ul><sub id='ywMCm'></sub></form><legend id='ywMCm'></legend><bdo id='ywMCm'><pre id='ywMCm'><center id='ywMCm'></center></pre></bdo></b><th id='ywMCm'></th></span></q></dt></tr></i><div id='ywMCm'><tfoot id='ywMCm'></tfoot><dl id='ywMCm'><fieldset id='ywMCm'></fieldset></dl></div>
                    <tbody id='ywMCm'></tbody>
                  本文介绍了取消 ListBox SelectedIndexChange 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以取消 Winforms 应用程序上列表框的 SelectedIndexChange 事件?这似乎是一件合乎逻辑的事情,以至于我必须忽略一些简单的功能.基本上,我一直在弹出一个消息框,询问用户是否真的想要移动到另一个项目,因为这会改变 UI,我不希望他们的更改丢失.如果用户没有保存他们正在处理的内容,我希望能够取消该事件.有更好的方法吗?

                  Is it possible to cancel the SelectedIndexChange event for a listbox on a winforms application? This seems like such a logical thing to have that I must be overlooking some easy feature. Basically, I have been popping up a message box asking if the user really wants to move to another item, as this will change the UI and I don't want their changes to be lost. I'd like to be able to cancel the event in case the user has not saved what they are working on. Is there a better way of doing this?

                  推荐答案

                  你不能取消它.

                  几天前我所做的是使用最新选择的索引创建一个变量.然后当事件触发时,您询问用户是否要保存,这是在事件处理程序中完成的.如果用户选择取消",您将再次更改 id.

                  What I did just a couple of days ago was to have a variable with the latest selected index. Then when the event fires, you ask the user if he wants to save, this is done in the eventhandler. If the user selected "Cancel" you change the id again.

                  问题是这会使事件再次触发.所以我使用的是一个布尔值,只是说抑制".在事件处理程序的顶部,我有:

                  The problem is that this will make the event fire once again. So what i've used is a bool just saying "Inhibit". And at the top of the eventhandler I have:

                  if(Inhibit)
                     return;
                  

                  然后在下面你问问题的地方你做这样的事情:

                  Then below this where you ask the question you do something like this:

                  DialogResult result = MessageBox.Show("yadadadad", yadada cancel etc);
                  if(result == DialogResult.Cancel){
                     Inhibit = true; //Make sure that the event does not fire again
                     list.SelectedIndex = LastSelectedIndex; //your variable
                     Inhibit = false; //Enable the event again
                  }
                  LastSelectedIndex = list.SelectedIndex; // Save latest index.
                  

                  这篇关于取消 ListBox SelectedIndexChange 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                  <tfoot id='3aS7Q'></tfoot>

                      • <bdo id='3aS7Q'></bdo><ul id='3aS7Q'></ul>

                        <small id='3aS7Q'></small><noframes id='3aS7Q'>

                        <i id='3aS7Q'><tr id='3aS7Q'><dt id='3aS7Q'><q id='3aS7Q'><span id='3aS7Q'><b id='3aS7Q'><form id='3aS7Q'><ins id='3aS7Q'></ins><ul id='3aS7Q'></ul><sub id='3aS7Q'></sub></form><legend id='3aS7Q'></legend><bdo id='3aS7Q'><pre id='3aS7Q'><center id='3aS7Q'></center></pre></bdo></b><th id='3aS7Q'></th></span></q></dt></tr></i><div id='3aS7Q'><tfoot id='3aS7Q'></tfoot><dl id='3aS7Q'><fieldset id='3aS7Q'></fieldset></dl></div>
                          <tbody id='3aS7Q'></tbody>

                          • <legend id='3aS7Q'><style id='3aS7Q'><dir id='3aS7Q'><q id='3aS7Q'></q></dir></style></legend>