在DataGridView的组合框的编程设置选择指数 [英] Programmatically set selected index of a ComboBox in DataGridView

查看:143
本文介绍了在DataGridView的组合框的编程设置选择指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,同时避免数据绑定,设置选定的指数在一个DataGridView组合框。它没有连接到一个数据库。

I want to, while avoiding databinding, to set the selected index in a ComboBox in a DataGridView. It is not connected to a DB.

我发现所有的解决方案都连接到一个数据库,这是我没有DataGridView的,所以我能不能解决问题。

All solutions I have found have the DataGridView connected to a Database, which I have not, so I couldn't solve the problem.

推荐答案

由于DataGridViewComboBoxColumn没有selectedIndex或SelectedValue的属性,你可以尝试这样设置的值,例如:

Since the DataGridViewComboBoxColumn has no SelectedIndex or SelectedValue properties, you can try and set the value like this example:

DataGridViewComboBoxColumn cmbCurrencies = (DataGridViewComboBoxColumn)myDataGridView.Columns["ComboboxCurrencyColumn"];

var currencies = entities.currencies.Select(c => c.currencyName).DefaultIfEmpty().ToList();     

cmbCurrencies.DataSource = currencies; 

和则:

for (int i = 0; i <= myDataGridView.RowCount - 1; i++)
    {
         myDataGridView.Rows[i].Cells["Index of Combobox Column"].Value = "Pound";
    }



也看看的这个可能会有帮助。

这篇关于在DataGridView的组合框的编程设置选择指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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