Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get ComboBox to update/refresh
    primarykey
    data
    text
    <p>I have 2 forms, which I'll call Form1 and Form2. In Form1 is the following code:</p> <pre><code>public void PrinterDD() { printer.Items.Clear(); string sprinters = @"filepath"; using (StreamReader reader = new StreamReader(sprinters)) try { while (!reader.EndOfStream) { string strPrnItem = reader.ReadLine(); MessageBox.Show(strPrnItem); //just here for troubleshooting purposes printer.Items.Add(strPrnItem); } } finally { reader.Close(); printer.Update(); printer.SelectedIndex = 0; } } </code></pre> <p>This method is called first when Form1 loads. The combobox ("printer") is populated correctly.</p> <p>In Form2, I have a method to write to the file and change it:</p> <pre><code>private void accept_Click(object sender, EventArgs e) { this.AcceptButton = accept; if (selectedprinters != null &amp;&amp; selectedprinters.Items != null &amp;&amp; selectedprinters.Items.Count &gt; 0) { File.Delete(sprinters); StreamWriter writer = new StreamWriter(sprinters); try { foreach (object item in selectedprinters.Items) { writer.WriteLine(item.ToString()); } } finally { writer.Close(); Voicemails.PrinterDD(); } } this.Close(); } </code></pre> <p>The line <code>Voicemails.PrinterDD();</code> runs the method from Form1 above. When stepping through the code, everything seems to work fine; no errors, the text file does get written with the new values. But the combobox never actually updates/refreshes to show the new strings.</p> <p>What am I doing wrong?</p> <p>EDIT. I have tried <code>printer.Refresh();</code> instead of <code>printer.Update();</code> in the Form1 code.</p> <p>ps. The file I'm using is a text file, so I don't think I'm able to bind the combobox to it, so I don't think doing <code>printer.DataSource = null</code> and then rebinding it would work.</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