本文介绍了如何将不同的DataSource绑定到DataGridViewComboBox单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataTable。



CurrencyId |货币

------------------ | ---------------------- ----------

0 | USD

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属性。我怎么才能得到它?谢谢。

解决方案

I have a DataTable.

CurrencyId | Currency
------------------|--------------------------------
0 | USD
1 | Baht
2 | Euro
5 | Rupee
6 | Yen

I have bound this table to a DataGridViewCombobox Cell. The user can choose one currency once. If the user choose 'USD' at first DataGridViewRow, the combobox of the next row would be without 'USD'. Can I get it? I have tried this.

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



i can't modify the DataSource Property. How can i get it? Thanks.

解决方案


这篇关于如何将不同的DataSource绑定到DataGridViewComboBox单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:32