如何从datagridview组合框获取值? [英] How to get value from datagridview combobox?

查看:97
本文介绍了如何从datagridview组合框获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

您可以使用:

  var value = DataGridView.Rows [0] .Cells [0] .Value 

注意:您将提供正确的行和单元格号。



或者,如果绑定到一个对象像ListItem

  string value = DataGridView.Rows [RowIndex] .Cells [ColumnIndex] .Value.ToString( ); 

如果DataGridView.Rows [RowIndex] .Cells [ColumnIndex]是DataGridViewComboBoxCell&&& !string.IsNullOrEmpty(value))
{
列表< ListItem> items =((DataGridViewComboBoxCellDataGridView.Rows [RowIndex] .Cells [e.ColumnIndex])。Items.Cast< ListItem>()。ToList();
ListItem item = items.Find(i => i.Value .Equals(value));
}


How to get value from datagridview combobox after selected value is changed?

解决方案

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));
}

这篇关于如何从datagridview组合框获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆