這裏是我的代碼:的DataGridViewComboBoxCell設定值,值無效
private class Person
{
private string myName;
private int myValue;
public Person(string name, int value)
{
myName = name;
myValue = value;
}
public override string ToString()
{
return myName;
}
public string Name
{
get { return myName; }
set { myName = value; }
}
public int Value
{
get { return myValue; }
set { myValue = value; }
}
}
我用它來填充的DataGridViewComboBoxCell這樣的:
myDataGridViewComboBoxCell.ValueMember = "Value";
myDataGridViewComboBoxCell.DisplayMember = "Name";
myDataGridViewComboBoxCell.Items.Add(new Person("blabla", someNumber));
所有我想現在要做的就是選擇一個人:
myDataGridViewComboBoxCell.Value = someNumber;
但不斷收到「值無效」 - 錯誤。任何想法爲什麼? 當我選擇在我的計劃,我可以看到正確的價值(someNumber),因此顯示和ValueMember正確設置項...
我無法在DataGridView上看到ValueType屬性。你的意思是'DataGridViewComboBoxColumn'? – Brij 2013-07-06 07:12:57
是的,它在'DataGridViewComboBoxColumn'上。 – 2014-03-14 18:03:05
@SimonDugré,感謝您的編輯。晚了。累。你知道...... – Spike 2014-10-07 01:18:30