DataGridViewComboBoxColumn添加不同项的每一行。 [英] DataGridViewComboBoxColumn adding different items to each row .

查看:1092
本文介绍了DataGridViewComboBoxColumn添加不同项的每一行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的DataGridView其中用户可以从每一个小区的下拉列表中选择的项目建立一个表。为了简化问题,可以说我有1列。我使用设计器中的DataGridViewComboBoxColumn。我想支持其在该列的每一行有一个项目不同列表选择。

I am building a table using the DataGridView where a user can select items from a dropdown in each cell. To simplify the problem, lets say i have 1 column. I am using the DataGridViewComboBoxColumn in the designer. I am trying to support having each row in that column have a different list of items to choose from.

这可能吗?

推荐答案

是的。这可以使用的DataGridViewComboBoxCell进行。

Yes. This can be done using the DataGridViewComboBoxCell.

下面是一个例子方法将项添加到只有一个细胞,而不是整个列

Here is an example method to add the items to just one cell, rather than the whole column.

private void setCellComboBoxItems(DataGridView dataGrid, int rowIndex, int colIndex, object[] itemsToAdd)
{
    DataGridViewComboBoxCell dgvcbc = (DataGridViewComboBoxCell) dataGrid.Rows[rowIndex].Cells[colIndex];
    // You might pass a boolean to determine whether to clear or not.
    dgvcbc.Items.Clear();
    foreach (object itemToAdd in itemsToAdd)
    {
        dgvcbc.Items.Add(itemToAdd);
    }
}

这篇关于DataGridViewComboBoxColumn添加不同项的每一行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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