1

I have written a GUI application that contains a DataGridView in which users can add new instances of an Arrow class by creating a new line in the view and filling in the new Arrow's properties. One of those properties is called transferType and is a string.

I allow users to set a list of valid transferTypes in a settings form. I am using Properties.Settings to save the settings, using the convent tool built into Visual Studio to create and manage application settings.

Rather than having the user enter the transferType field by hand and have the DataGridView reject the entry if it does not match any of the valid transferTypess, 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 DataGridViewTextBoxColumn to DataGridViewComboBoxColumn. That change allows me to select a DataSource to populate the selections of the combo box, so I went and under "Other data sources" attempt to select "Properties" which stores my settings (Properties.Settings.Default), but for some reason Visual Studio won't allow me to select it.

I then tried set the DataSource of the combo box in code after the initialization of the GUI, using the line" ((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes; (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":

The following exception occured in the DataGridVIew: System.ArgumentException: DataGridViewComboBoxCell value is not valid. To replace this default dialog please handle to DataError event.

The error loops and reappears immediately after hitting OK or exiting the window.

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 DataSource using Properties. Any help would be appreciated.

(This is also my first posted question, so be gentle with the criticism please :) )

UPDATE: It turns out that using ((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes; does correctly populate the combo box, but any time the combo box is moused over, the previously mentioned error comes up.

thegman121
  • 71
  • 5

1 Answers1

0

If you are using Properties.Settings.validTransferTypes as a string then the value of that combobox would only be a single string value. Do you have more values in your settings that you'd like to populate the combobox with? It seems that the error is coming because you have nothing else for the combobox to read other that the single string you are loading in. Trying to load an array with Properties.Settings.Default may be an option and then setting the datasource equal to that array.

cshemby
  • 200
  • 4