I am trying to bind a DataGridViewComboBox to a list for hours now.
But a
"Value is not valid"-Error-Dialog is everything I get :(
From my local oracle-test-database I am fetching some data. Everything works fine but the combobox. I want the combobox to show the – sometimes – in the db chosen value and let the user change the value via the combobox.
I have a class called DtoPerson:
internal class DtoPerson
{
private String _name;
private Int32 _personRollenId;
public String Name
{
get { return _name; }
set { _name = value; }
}
public Int32 PersonRollenId
{
get { return _personRollenId; }
set { _personRollenId = value; }
}
}
I am filling a list of DtoPersons within this method:
private void CreateList()
{
DataRow[] treiberRows = _personTable.Select("ROLLE = '2'", "PERSONNAME ASC", DataViewRowState.CurrentRows);
_aufbauerListe = new List<DtoPerson>();
if (treiberRows != null && treiberRows.Length > 0)
{
foreach (DataRow row in treiberRows)
{
DtoPerson person = new DtoPerson();
//Füllen der Felder
person.Name = row["PERSONNAME"].ToString();
int persoId;
Int32.TryParse(row["PERSROLLID"].ToString(), out persoId);
person.PersonRollenIdInt = (persoId > 0) ? persoId : -1;
_aufbauerListe.Add(person);
}
}
}
´After´ loading all data, I am Binding the ComboBox to the List:
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DataSource = DaPerson.Instance.AufbauerListe;
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DisplayMember = "Name";
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).ValueMember = "PersonRollenId";
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DataPropertyName = "AUFBAUERID";
Now every time i choose a value, or there should be a prechosen value, the above mentioned error is displayed. How can I solve this?
I really need help here…
Meanwhile I found my mistake:
The OracleXE send my value as an
Decimal, a type I never heard / dreamed of… …now by changing the Id-Property toeverything works just fine.
It’s a pitty, that DataTables don’t show what kind of types they inherit…