• <bdo id='0iVvW'></bdo><ul id='0iVvW'></ul>
      <legend id='0iVvW'><style id='0iVvW'><dir id='0iVvW'><q id='0iVvW'></q></dir></style></legend>
      <tfoot id='0iVvW'></tfoot>
    1. <small id='0iVvW'></small><noframes id='0iVvW'>

      <i id='0iVvW'><tr id='0iVvW'><dt id='0iVvW'><q id='0iVvW'><span id='0iVvW'><b id='0iVvW'><form id='0iVvW'><ins id='0iVvW'></ins><ul id='0iVvW'></ul><sub id='0iVvW'></sub></form><legend id='0iVvW'></legend><bdo id='0iVvW'><pre id='0iVvW'><center id='0iVvW'></center></pre></bdo></b><th id='0iVvW'></th></span></q></dt></tr></i><div id='0iVvW'><tfoot id='0iVvW'></tfoot><dl id='0iVvW'><fieldset id='0iVvW'></fieldset></dl></div>
      1. C# 强制 ListBox 更新元素

        时间:2023-10-07
          <bdo id='2iBPh'></bdo><ul id='2iBPh'></ul>

        • <small id='2iBPh'></small><noframes id='2iBPh'>

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

                  本文介绍了C# 强制 ListBox 更新元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在继承标准 ListBox 控件.我会收到有关添加到列表中的任何元素的更改的通知.任务是更新列表框显示的文本以用于更改元素.

                  I'm subclassing the standard ListBox control. I get notified of changes to any of the elements added to the list. The task is to update the text shown by the ListBox for the changing element.

                  我知道我可以删除更改的元素并重新添加它,但由于显而易见的原因,这似乎并不可取.

                  I'm aware that i could just remove the changed element and add it again, but this seems not preferable for obvious reasons.

                  推荐答案

                  很遗憾,ListView 中的数据绑定不支持常规(项目)更改通知事件(FooChanged/<代码>INotifyPropertyChanged).但是,如果您知道更改,您可以让列表重新绑定自身.由于您是子类化,您可以调用:

                  Unfortunately, the data-binding in ListView doesn't support regular (item) change notification events (FooChanged / INotifyPropertyChanged). However, if you know about the change, you can get the list to re-bind itself. Since you are subclassing, you can call:

                  this.RefreshItems();
                  

                  或单个项目:

                  this.RefreshItem(index);
                  

                  否则,由于这不是公开的,您可以通过更改 DisplayMember 来模拟它:

                  Otherwise, since this isn't public, you can simulate it by changing the DisplayMember:

                  lb.DisplayMember = "";
                  lb.DisplayMember = "Bar";
                  

                  可能有点 hacky,但它可以工作,并保持当前选择等(不像清除 DataSource).

                  A little hacky, maybe, but it works, and maintains the current selection etc (unlike clearing the DataSource).

                  这篇关于C# 强制 ListBox 更新元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    1. <tfoot id='mf4jy'></tfoot>
                        <tbody id='mf4jy'></tbody>

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

                        • <legend id='mf4jy'><style id='mf4jy'><dir id='mf4jy'><q id='mf4jy'></q></dir></style></legend>

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