Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Properties.Settings as a datasource in C# (specifically for a DataGridViewComboBoxColumn)
    primarykey
    data
    text
    <p>I have written a GUI application that contains a DataGridView in which users can add new instances of an <code>Arrow</code> class by creating a new line in the view and filling in the new <code>Arrow</code>'s properties. One of those properties is called <code>transferType</code> and is a string.</p> <p>I allow users to set a list of valid <code>transferType</code>s in a settings form. I am using <code>Properties.Settings</code> to save the settings, using the convent tool built into Visual Studio to create and manage application settings.</p> <p>Rather than having the user enter the <code>transferType</code> field by hand and have the DataGridView reject the entry if it does not match any of the valid <code>transferTypes</code>s, I have been trying to set up the column of the DataGridView to use drop down menus populated with the valid options. To do this, using Visual Studios GUI Design tool(which was used to build the GUI) I edited the column and changed the "Column Type" from <code>DataGridViewTextBoxColumn</code> to <code>DataGridViewComboBoxColumn</code>. That change allows me to select a <code>DataSource</code> to populate the selections of the combo box, so I went and under "Other data sources" attempt to select "Properties" which stores my settings (<code>Properties.Settings.Default</code>), but for some reason Visual Studio won't allow me to select it.</p> <p>I then tried set the <code>DataSource</code> of the combo box in code after the initialization of the GUI, using the line" <code>((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes;</code> (Transfer Type is the fourth column), but when I ran my program I get this error when I click on the combo box and try to "drop it down":</p> <p>The following exception occured in the DataGridVIew: System.ArgumentException: DataGridViewComboBoxCell value is not valid. To replace this default dialog please handle to DataError event.</p> <p>The error loops and reappears immediately after hitting OK or exiting the window.</p> <p>I'm assuming that there has to be a reasonable way to use my settings to populate a combo box, but can't figure out how. I also don't understand why Visual Studio won't allow me to create a <code>DataSource</code> using <code>Properties</code>. Any help would be appreciated.</p> <p>(This is also my first posted question, so be gentle with the criticism please :) )</p> <p>UPDATE: It turns out that using <code>((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes;</code> does correctly populate the combo box, but any time the combo box is moused over, the previously mentioned error comes up.</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