Note that there are some explanatory texts on larger screens.

plurals
  1. POCombobox crashes when selecting item with keyboard
    primarykey
    data
    text
    <p>I have a problem with the code below, basically what is does is read from a path where files with extension .config are stored, it reads the names of the files without extension and displays them all in a combobox. That works fine and if you click on the down arrow and select a name it actually does what it's supposed to, however, once I have selected an item from the dropdown with the mouse and I go back and start typing inside the combobox my application crashes throwing a exception.</p> <p>I've tried adding a try-catch-finally but it keeps throwing the same error. Could it be the loop that is causing my application to crash once I start typing in the combobox?</p> <p>p.d. If I just use the mouse to select an item from the dropdown menu my application works fine but once I've selected an item with the mouse and use the keyboard to type another item name inside the combobox my app crashes. Any pointers would be helpful.</p> <pre><code>// Gets all the file names from the path assigned to templatePath // and assigns it to the string array fname string[] fname = Directory.GetFiles(templatePath); // Begin sorting through the file names assigned to the string array fname foreach (string file in fname) { // Remove the extension from the file names and compare the list with // the dropdown selected item if (System.IO.Path.GetFileNameWithoutExtension(file) == cbTemplates.SelectedItem.ToString()) { // StreamReader gets the contents from the found file and assigns // them to the labels using (var obj = new StreamReader(File.OpenRead(file))) { lbl1.Content = obj.ReadLine(); lbl2.Content = obj.ReadLine(); lbl3.Content = obj.ReadLine(); lbl4.Content = obj.ReadLine(); lbl5.Content = obj.ReadLine(); lbl6.Content = obj.ReadLine(); lbl7.Content = obj.ReadLine(); lbl8.Content = obj.ReadLine(); lbl9.Content = obj.ReadLine(); lbl10.Content = obj.ReadLine(); obj.Dispose(); } } } </code></pre>
    singulars
    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.
 

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