user396716
user396716

Reputation:

How to get value from datagridview combobox?

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

Upvotes: 3

Views: 21000

Answers (2)

Semih Can Bilgen
Semih Can Bilgen

Reputation: 414

Do not pass to give column name

 string SelectedText = Convert.ToString((Pass_dataGridView.Rows[0].Cells["Partner"] as DataGridViewComboBoxCell).FormattedValue.ToString());

Upvotes: 0

Alex Mendez
Alex Mendez

Reputation: 5150

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

Upvotes: 4

Related Questions