• <tfoot id='ruQxQ'></tfoot>
      <bdo id='ruQxQ'></bdo><ul id='ruQxQ'></ul>

      <legend id='ruQxQ'><style id='ruQxQ'><dir id='ruQxQ'><q id='ruQxQ'></q></dir></style></legend>
    1. <small id='ruQxQ'></small><noframes id='ruQxQ'>

      1. <i id='ruQxQ'><tr id='ruQxQ'><dt id='ruQxQ'><q id='ruQxQ'><span id='ruQxQ'><b id='ruQxQ'><form id='ruQxQ'><ins id='ruQxQ'></ins><ul id='ruQxQ'></ul><sub id='ruQxQ'></sub></form><legend id='ruQxQ'></legend><bdo id='ruQxQ'><pre id='ruQxQ'><center id='ruQxQ'></center></pre></bdo></b><th id='ruQxQ'></th></span></q></dt></tr></i><div id='ruQxQ'><tfoot id='ruQxQ'></tfoot><dl id='ruQxQ'><fieldset id='ruQxQ'></fieldset></dl></div>
      2. ListBox 和 Datasource - 防止第一个项目被选中

        ListBox and Datasource - prevent first item from being selected(ListBox 和 Datasource - 防止第一个项目被选中)

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

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

                  本文介绍了ListBox 和 Datasource - 防止第一个项目被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  嘿.我有以下代码填充我的列表框

                  Hey. I've got the following code that populates my list box

                  UsersListBox.DataSource = GrpList;
                  

                  但是,在填充该框后,默认选择列表中的第一项,并触发选择的索引已更改"事件.如何防止在填充列表框后立即选择项目,或者如何防止触发事件?

                  However, after the box is populated, the first item in the list is selected by default and the "selected index changed" event fires. How do I prevent the item from being selected right after the list box was populated, or how do I prevent the event from firing?

                  谢谢

                  推荐答案

                  为了防止事件触发,这里有两个我过去使用过的选项:

                  To keep the event from firing, here are two options I have used in the past:

                  1. 在设置 DataSource 时取消注册事件处理程序.

                  1. Unregister the event handler while setting the DataSource.

                  UsersListBox.SelectedIndexChanged -= UsersListBox_SelectedIndexChanged;
                  UsersListBox.DataSource = GrpList;
                  UsersListBox.SelectedIndex = -1; // This optional line keeps the first item from being selected.
                  UsersListBox.SelectedIndexChanged += UsersListBox_SelectedIndexChanged;
                  

                1. 创建一个布尔标志以忽略该事件.

                2. Create a boolean flag to ignore the event.

                  private bool ignoreSelectedIndexChanged;
                  private void UsersListBox_SelectedIndexChanged(object sender, EventArgs e)
                  {
                      if (ignoreSelectedIndexChanged) return;
                      ...
                  }
                  ...
                  ignoreSelectedIndexChanged = true;
                  UsersListBox.DataSource = GrpList;
                  UsersListBox.SelectedIndex = -1; // This optional line keeps the first item from being selected.
                  ignoreSelectedIndexChanged = false;
                  

                3. 这篇关于ListBox 和 Datasource - 防止第一个项目被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 列表框上的取消选择)

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

                  <tfoot id='xnkDw'></tfoot>

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

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