DataGridViewが1つあり、DataGridViewに1つのDataGridViewComboBoxColumnがあるとします。 私は、データグラムのコンボボックスに国名とコードを入力しています。DataGridViewComboBoxColumnから値とテキストを選択します。C#
これで、私は、私がDataGridViewComboBoxColumnの値とテキストを選択したいと思っています。値を取得できませんでしたが、forループのDataGridViewComboBoxColumnから表示テキストを取得できませんでした。
可能であれば、小さなコードで助けてください。
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= dgList.Rows.Count - 1; i++)
{
DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell;
int index = cell == null || cell.Value == null ? -1 : cell.Items.IndexOf(cell.Value);
string strVal = cell.Value.ToString();
}
}
おかげ
方法例えば
dgList [ "COLUMNNAME"、rowIndexに] .Valueの
をあなたはコンボボックスの列に値をバインドしていますか? – V4Vendetta