Slow showing / drawing dialogue with ListBox?

后端 未结 3 1482
执念已碎
执念已碎 2021-01-27 16:09

My application uses entity framework to pull in a small tiny set of results... It takes about 3 seconds for it to do it? Why might this be?

Start.cs

3条回答
  •  清歌不尽
    2021-01-27 16:45

    The ListBox has to redraw every time you add an item. You can either use Dmitry's method of using AddRange(), or you can wrap your loop with BeginUpdate()/EndUpdate() calls.

    ListBoxProjectType.BeginUpdate();
    
    foreach( var projectType in projectTypes )
    {
        ListBoxProjectType.Items.Add(projectType.Title);
    }
    
    ListBoxProjectType.EndUpdate();
    

提交回复
热议问题