Listbox Update () in C #

int[] arr = int[100]; listBox1.DataSource = arr; void ComboBox1SelectedIndexChanged(object sender, EventArgs e) { .....//some processes listBox1.DataSource = null; listBox1.DataSource = arr; } is not working, 

and

 listBox1.Refresh(); is not working, 

and

 listBox1.Update(); is not working, 


I know that I can use BindingList<T> , but I need to work only with the array.

Can you help me, how can I update the list?

+8
c # refresh listbox
source share
10 answers

try the following

 listBox1.DataBind() 
0
source share

my first answer to stack exchange is here.

C # .Net 4.0:

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

I noticed that installing the data source for the first time, it is being updated. When it is installed, and try again to install it on one, it will not update.

So, I made it null, set it to the same thing, and it correctly displayed this problem for me.

+10
source share

Only managed with

 FirstListBox.DataContext = null; FirstListBox.DataContext = App.ViewModel; 

It just loses touch and returns all the data.

+2
source share

The ListBox only updates the displayed content when the object bound to the dataSource object has its own changes. The BindingSource object has an event called DataSourceChanged. when the source is changed to another object, the Listbox will update itself. Same thing when you bind a list. Nothing will happen if you change the List because the List does not report that it has been changed. There is a simple solution to this problem: use the BindingList http://msdn.microsoft.com/de-de/library/ms132679%28v=vs.110%29.aspx

The BindingList has a ListChanged event that is raised every time the list changes (obviously). Thus, DataBindings for Windows.Form objects use events like ListChanged to update themselves. A simple list does not support this event.

SO, if you want to work with a lot of data bindings that you should know about: http://msdn.microsoft.com/de-de/library/system.componentmodel.inotifypropertychanged%28v=vs.110%29.aspx

+2
source share
+1
source share

Well, without binding, I managed to:

 this.Hide(); this.Show(); 

he redraws everything ...

+1
source share

The problem may arise from the ListBox SelectionMode.

For some reason I don't know, data binding does not work when SelectionMode is SelectionMode.None.

Workaround may be:

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

Hope this helps.

+1
source share

Use BeginUpdate and EndUpdate which should solve this problem. No need to install data source twice

 listBox1.BeginUpdate(); listBox1.DataSource = myList; listBox1.EndUpdate(); 
0
source share

I inherited the ListBox and added a public method that calls RefreshItems() , which does what we want. Already implemented and all. I do not know why they did not become a public method.

0
source share

Windows forms to see changes, especially in Listbox and other controls before the download is complete, are complex. To see the data as loaded, use invalidate (); then Update ();

0
source share

All Articles