Note that there are some explanatory texts on larger screens.

plurals
  1. POListBox has set datasource but Refresh does nothing
    primarykey
    data
    text
    <p>I seem to be misunderstanding the ListBox.Refresh() method and I was hoping someone could help me out.</p> <p>What I am trying to do:<br> I want to load a listbox's data (source = table of a sql database) upon initialization of a windows form. Also when the user adds data to the database I would like the listbox to update.</p> <p>Logic:<br> I have a sql database as my source, it is set as:</p> <pre><code>listBoxDays.DataSource = DBQuery.informationRetreval().DefaultView; </code></pre> <p>DBquery.informationRetreval() is a static method within the my DBQuery static class. All it does is set up a table from the database and then returns the table.</p> <p>I set the datasource within the same method as the initializeComponent (so my listbox will load with the existing data):</p> <pre><code>public Settings() { InitializeComponent(); listBoxDays.DataSource = DBQuery.informationRetreval().DefaultView; } </code></pre> <p>When the user adds more data: I call a method in which I add the data to the database and then I call:</p> <pre><code> listBoxDays.Refresh(); //update listbox </code></pre> <p>The Problem: This does not update the listbox. Upon initialization of my listbox the data will populate but after it will not change (hence refresh does not work). Why is that? I could set the DataSource again but that feels sloppy. After looking into some of the documentation I noticed the event handler DataSourceChanged which maybe more for what I am looking for. Nevertheless why wouldn't refresh work?</p> <p>Thank you for your patience. Please let me know if I need to be more clear.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload