listbox Refresh() in c#

前端 未结 10 2350
梦毁少年i
梦毁少年i 2020-12-30 10:54
int[] arr = int[100];
listBox1.DataSource = arr;
void ComboBox1SelectedIndexChanged(object sender, EventArgs e)
{
    .....//some processes
    listBox1.DataSource =         


        
相关标签:
10条回答
  • 2020-12-30 11:35

    The problem might come from the ListBox SelectionMode.

    For a reason that I don't know, the databinding does not work when SelectionMode is SelectionMode.None.

    A workaround could be:

    listBox.SelectionMode = SelectionMode.MultiExtended;
    listBox.DataSource = myDatasource;
    listBox.SelectionMode = SelectionMode.None;
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-30 11:44

    try the following

    listBox1.DataBind()
    
    0 讨论(0)
  • 2020-12-30 11:45

    Use BeginUpdate and EndUpdate, that should solve it. No need to set the data source twice

    listBox1.BeginUpdate();
    
    listBox1.DataSource = myList;
    
    listBox1.EndUpdate();
    
    0 讨论(0)
  • 2020-12-30 11:46

    my first answer on stack exchange here.

    C# .Net 4.0:

    listBox1.DataSource = null;
    listBox1.DataSource = names;
    

    I noticed that setting the datasource for the first time, it refreshes. When it's set, and you try set it to the same one again, it doesn't update.

    So I made it null, set it to the same one, and it displayed correctly for me with this issue.

    0 讨论(0)
提交回复
热议问题