C# 如何从datagridview组合框中获取值?
更改选定值后如何从datagridview组合框中获取值?您可以使用:C# 如何从datagridview组合框中获取值?,c#,datagrid,C#,Datagrid,更改选定值后如何从datagridview组合框中获取值?您可以使用: var value = DataGridView.Rows[0].Cells[0].Value 注意:请提供正确的行和单元格编号 或者,如果它绑定到类似ListItem的对象,则可以执行类似的操作 string value = DataGridView.Rows[RowIndex].Cells[ColumnIndex].Value.ToString(); if DataGridView.Rows[RowIndex].Ce
var value = DataGridView.Rows[0].Cells[0].Value
注意:请提供正确的行和单元格编号
或者,如果它绑定到类似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 value=DataGridView.Rows[RowIndex]。单元格[ColumnIndex]。value.ToString();
如果DataGridView.Rows[RowIndex].Cells[ColumnIndex]是DataGridViewComboxCell&!string.IsNullOrEmpty(值))
{
列表项=((DataGridViewComboBoxCellDataGridView.Rows[RowIndex].Cells[e.ColumnIndex]).items.Cast().ToList();
ListItem=items.Find(i=>i.Value.Equals(Value));
}
您可以使用:
var value = DataGridView.Rows[0].Cells[0].Value
注意:请提供正确的行和单元格编号
或者,如果它绑定到类似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 value=DataGridView.Rows[RowIndex]。单元格[ColumnIndex]。value.ToString();
如果DataGridView.Rows[RowIndex].Cells[ColumnIndex]是DataGridViewComboxCell&&!string.IsNullOrEmpty(值))
{
列表项=((DataGridViewComboBoxCellDataGridView.Rows[RowIndex].Cells[e.ColumnIndex]).items.Cast().ToList();
ListItem=items.Find(i=>i.Value.Equals(Value));
}
不要传递给列名称
string SelectedText = Convert.ToString((Pass_dataGridView.Rows[0].Cells["Partner"] as DataGridViewComboBoxCell).FormattedValue.ToString());
不要传递给列名称
string SelectedText = Convert.ToString((Pass_dataGridView.Rows[0].Cells["Partner"] as DataGridViewComboBoxCell).FormattedValue.ToString());
我尝试在CellContentClick事件中读取,但未成功。在选定值更改后如何读取。尝试使用CellValueChanged事件。我尝试在CellContentClick事件中读取,但未成功。在选定值更改后如何读取。尝试使用CellValueChanged事件。