1

我有一个数据表。

货币 ID | 货币


0 | 美元

1 | 铢

2 | 欧元

5 | 卢比

6 | 日元

我已将此表绑定到 DataGridViewCombobox 单元格。用户可以选择一种货币一次。如果用户在第一个 DataGridViewRow 中选择“USD”,则下一行的组合框将没有“USD”。我能得到它吗?我试过这个。

 private void setCellComboBoxItems(DataGridView dataGrid, int rowIndex, int colIndex,   DataTable itemsToAdd)
  {
      DataGridViewComboBoxCell currencycell = (DataGridViewComboBoxCell)dataGrid.Rows[rowIndex].Cells[colIndex];

      currencycell.DataSource = dtCurrency;
      currencycell.ValueMember = "CurrencyId";
      currencycell.DisplayMember = "CurrencyShortName";
  }

我无法修改 DataSource 属性。我怎么才能得到它?谢谢。

4

1 回答 1

0

拥有数据源的副本,您可以在其中删除用作显示数据源的选定值。

订阅DataGridView.EditingControlShowing事件,然后从编辑控件中获取组合框,如下所示,并将其数据源设置为数据源的副本。

示例代码:

void myDGV_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        ComboBox comboBox = e.Control as ComboBox;
        if (comboBox != null)
        {
            comboBox.DataSource = displayDataSource;
        }
    }
于 2014-01-20T11:11:35.683 回答