更改选定值后如何从datagridview组合框中获取值?
You can use:
var value = DataGridView.Rows[0].Cells[0].Value
NOTE: You would supply the correct row and cell number.
Or you can do something like this if it is bound to an object like ListItem
string value = DataGridView.Rows[RowIndex].Cells[ColumnIndex].Value.ToString();
if DataGridView.Rows[RowIndex].Cells[ColumnIndex] is DataGridViewComboBoxCell && !string.IsNullOrEmpty(value))
{
List<ListItem> items = ((DataGridViewComboBoxCellDataGridView.Rows[RowIndex].Cells[e.ColumnIndex]).Items.Cast<ListItem>().ToList();
ListItem item = items.Find(i => i.Value.Equals(value));
}
不传给列名
string SelectedText = Convert.ToString((Pass_dataGridView.Rows[0].Cells["Partner"] as DataGridViewComboBoxCell).FormattedValue.ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.