[英]Listbox items “invisibles” when refreshing data (winform)
I have a problem with my listbox : if I change anything in the data (like adding an item or deleting one), the items become invisble but actually is still "here" (I can see it because I have made a sort of tooltip when my mouse go hover it). 我的列表框有问题:如果我更改了数据中的任何内容(例如添加一项或删除一项),则这些项目将变得不可见,但实际上仍在“此处”(我可以看到它,因为当我的鼠标悬停它)。
The purpose of my listbox is to show a list of scene (like files) when the user select an folder with a combobox. 我的列表框的目的是在用户选择带有组合框的文件夹时显示场景列表(如文件)。
Here is my code : 这是我的代码:
public partial class FormScenario : Form
{
BindingList<Folder> blFolders = new BindingList<Folder>();
BindingList<Scene> blScenes = new BindingList<Scene>();
public FormScenario(FormMainPanel fParent)
{
InitializeComponent();
FParent = fParent;
}
public void Refresh_blScenes()
{
lb_scenes.DataSource = null;
lb_scenes.Items.Clear();
lb_scenes.DataSource = this.blScenes;
lb_scenes.DisplayMember = "SceneName";
//attempt to fix the bug ... not working
lb_scenes.DrawMode = DrawMode.Normal;
lb_scenes.DrawMode = DrawMode.OwnerDrawFixed;
}
public void Populate_Scene_Datas()
{
blScenes.Clear();
Folder fol = (Folder)cb_listfolders.SelectedItem;
if (fol != null){
foreach (Scene sce in fol.ListScenes){
this.blScenes.Add(sce);
}
}
}
}
If it is useful, there is my objects : 如果有用,这里是我的对象:
class Folder
{
public Int32 IdFolder { get; set; }
public String FolderName { get; set; }
public String FolderInfo { get; set; }
// contains the list to show in the listbox
public List<Scene> ListScenes = new List<Scene>();
}
class Scene
{
public Int32 IdScene { get; set; }
public String SceneName { get; set; }
public byte[] SceneDesc { get; set; }
public byte[] SceneInfo { get; set; }
}
I use these functions in the following order : 我按以下顺序使用这些功能:
Populate_Scene_Datas();
Refresh_blScenes();
if somebody give me a hint or a answer at this problem, it will be very helpfull ! 如果有人对这个问题给我一个提示或答案,那将非常有帮助!
Thanks you ! 谢谢 !
I have found a solution... but I can't explain why it is working. 我找到了解决方案...但是我无法解释为什么它起作用。 I'm posting this if someone encounter the same problem. 如果有人遇到相同的问题,我将发布此信息。
I have change this : 我已经改变了:
lb_scenes.DataSource = this.blScenes;
by : 创建人:
lb_scenes.Items.AddRange(blScenes.ToArray());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.