I have a big problem that make me so confuse that I have a DataGridView without using binding which has DataGridViewComboBoxColumn (unbound column) and I want to get selected index or selected item in the ComBoBoxCell (my item i custom item).
I try to cast or follow this website (http://satishjdotnet.blogspot.com/2009/05/getting-selected-value-of-combo-box-in.html) but I only recieve Error:
"Value is not invalid"
. So how can I solve it? Please help me. Thanks a lot. Here is my custom Item in combobox:
public class CustomItem {
public string Text { get; set; }
public object Value { get; set; }
public override string ToString() {
return Text;
}
public CustomItem(string text, object value) {
this.Text = text;
this.Value = value;
}
}
and how I add it to DataGridViewComboBoxColumn:
List<CustomItem> teamItem = new List<CustomItem>();
teamItem.Add(new CustomItem(this._homeTeam["Name"].ToString(), Convert.ToInt32(this._homeTeam["Id"])));
teamItem.Add(new CustomItem(this._awayTeam["Name"].ToString(), Convert.ToInt32(this._awayTeam["Id"])));
foreach (CustomItem i in teamItem) {
((DataGridViewComboBoxColumn)this.dataGridViewGoalInformation.Columns["Team"]).Items.Add(i);
}