简体   繁体   English

当我将ListBox SelectionMode设置为“ None”时,它不会对DataSource的更改做出反应

[英]When I set the ListBox SelectionMode to “None”, it doesn't react to DataSource changes

while searching for an answer, I found out it's an old "bug" in VS !(?) I am using VS2013. 在寻找答案时,我发现这是VS 2013中的旧“错误”!(?)我正在使用VS2013。 I simply don't believe that they didn't correct it, so I have to think it's intentional, or there's something I am not doing right... 我只是不相信他们没有纠正它,所以我必须认为这是故意的,否则我做错了某些事情...

I want to use ListBox to dislpay some simple results. 我想使用ListBox来显示一些简单的结果。 I want that list to be read-only, items not selectable and so on. 我希望该列表为只读,无法选择项目,依此类推。 Just a display of a simple array of results. 仅显示一个简单的结果数组。

I use an array as a datasource (lstBox.DataSource = somearray;), which I update by setting DataSource to null, then back to somearray. 我使用数组作为数据源(lstBox.DataSource = somearray;),我通过将DataSource设置为null,然后又返回somearray来进行更新。 The problem is - if I set the listBox SelectionMode to "none", list gets stuck and it doesn't refresh anymore. 问题是-如果我将listBox SelectionMode设置为“ none”,列表将卡住,并且不再刷新。 I can't refresh it. 我无法刷新。 If I set list as "disabled" instead, it's showing the results correctly, it's not selectable, no matter what SelectionMode says, but it's all greyed out... Any help on this ? 如果我将list设置为“ disabled”,则无论SelectionMode说什么,它都会正确显示结果,它是不可选择的,但是它都是灰色的...对此有任何帮助吗?

ps from what I've read, even setting datasource to BindingList or BindingSource doesn't rectify this problem... 从我读到的内容来看,即使将数据源设置为BindingList或BindingSource也无法解决此问题。

SelectionMode does not have a None value in WPF. SelectionMode在WPF中None (although it had in WinForms ) (尽管它在WinForms中

In WPF, if you want to present items without allowing selection, you should use the ItemsControl class instead of the ListBox . 在WPF中,如果要显示项目而不允许选择,则应使用ItemsControl类而不是ListBox

But I'm not sure whether you are using WPF or WinForms by reading your question. 但是我不确定您是通过阅读问题来使用WPF还是WinForms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当SelectionMode =“ Extended”时,DataGrid无法正确取消选择隐藏项 - DataGrid doesn't deselect hidden items properly when SelectionMode=“Extended” DataSource更改时,ComboBox不会自动更新? - ComboBox doesn't automatically update when DataSource changes? 设置DataSource时从ListBox中删除项目 - Remove items from ListBox when DataSource is set ListBox.DataSource不在列表上显示数据 - ListBox.DataSource doesn't show data on the list 更新数据源后,列表框不显示新行 - Listbox doesn't show new row after updating the datasource 当SelectionMode设置为Multiple时,更改ListViewItems样式 - Change ListViewItems style when SelectionMode is set to Multiple 使用SelectionMode = Extended选择列表框 - Listbox IsSelected with SelectionMode=Extended 为什么在使用EndCurrentEdit时第一次更改数据源时绑定值是否仍然存在? - Why doesn't a bound value persist to the datasource the first time it changes when using EndCurrentEdit? 设置数据源时,从列表框中删除列表中的元素 - Deleting a Element in a List from a Listbox when the Datasource is Set 列表框错误:设置了DataSource属性时,无法修改项目集合 - listbox error: Items collection cannot be modified when the DataSource property is set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM