问题描述
在一个win表单应用程序中,我正在加载一个名为dg的datagridview,这个数据来自一个名为servRet的数据源。servRet填入数据网格。在将dg.datasource设置为servRet.value之后,我正在创建一个类型为DataGridViewComboBoxColumn的新列,它将来可以容纳硬币类型(例如:CAD,US,NIS ......)。
现在,这是一个棘手的部分:
组合框假设从servRet显示displayValue但是当客户端打开组合框时,他需要看到所有的硬币列表。
硬币列表是从另一个名为servRet1的数据源中拖出的。
我试图完成组合框显示当前当前值的状态在servRet中行,同时用第二个数据源填充组合项。
不幸的是,我遇到了几个问题:
1.我试过将servRet1传递给列表并将其加载到组合但我无法将项目添加到绑定的组合框。
2.我无法将2个数据源加载到一个组合框。
3.即使将servRet加载到组合框中并且在拖动打开时我将组合数据源设置为null并加载servRet1,在selectedIndexChange上,它不允许我选择任何其他值而不是然后它持有的第一个值。
这里是t他加载第一个数据的代码:
public void FillData(IShaarimService服务)
{
List< string> listTeuraMatbea = new List< string>();
List< string> listKodAndShemMatbea = new List< string>();
var servRet = service.getNiyarotBeMatbeaShoneMeBank();
var servRet1 = service.getMatbeaot();
if (ServiceUtil.IsValid(servRet1))
{
foreach (DataRow row in servRet1.Value.Rows)
{
listKodAndShemMatbea.Add(row [& QUOT; KodAndShemMatbea&安培; QUOT]的ToString());
listTeuraMatbea.Add(row [& quot; TeuraMatbea& quot;]。ToString());
}
}
if (ServiceUtil.IsValid(servRet))
{
grdNiyar.SetDataSourceByServerReturn(servRet);
dg.AutoGenerateColumns = false ;
dg.ColumnCount = 4 ;
dg.DataSource = servRet.Value;
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
cb.DataSource = servRet.Value.DefaultView.ToTable( true ,KodAndShemMatbea&);
// foreach(listKodAndShemMatbea中的var项目)
// {
// cb.Items.Add(item);
// }
cb.HeaderText =& quot;מטבעבבנק& quot ;;
cb.DisplayMember =& quot; 123& quot ;;
cb.DataPropertyName =& quot; KodAndShemMatbea& quot ;;
cb.DisplayMember =& quot; KodAndShemMatbea& quot ;;
cb.ValueMember =& quot; KodAndShemMatbea& quot ;;
dg.Columns.Add(cb);
} < / pre >
我们非常感谢任何帮助!!!
hey!
in a win forms application, i'm loading a datagridview called dg from a data source called servRet.
the servRet fills in the data grid. after setting the dg.datasource to servRet.value, i'm creating a new column of type DataGridViewComboBoxColumn which future to hold types of coins (e.g: CAD, US, NIS...).
Now, here is the tricky part:
the combo box suppose to display the displayValue from the servRet but when the client open the combo box, he needs to see all the coins list.
the coins list is dragged from another data source called servRet1.
i'm seek to accomplish a state where the combo box display the current value from the current row in the servRet and at the same time fill the item of the combo with the second data source.
unfortunately, i ran into several problems:
1. i tried to pass the servRet1 to a list and the load it to the combo but i cant add items to a binded combo box.
2. i cant load 2 data sources to one combo box.
3. even when loading the servRet to the combo box and on the drag open i'm setting the combo data source to null and load the servRet1, on the selectedIndexChange, it doesn't allow me to choose any other value rather then the first value it held.
here is the code for loading the first data:
public void FillData(IShaarimService service) { List<string> listTeuraMatbea = new List<string>(); List<string> listKodAndShemMatbea = new List<string>(); var servRet = service.getNiyarotBeMatbeaShoneMeBank(); var servRet1 = service.getMatbeaot(); if (ServiceUtil.IsValid(servRet1)) { foreach (DataRow row in servRet1.Value.Rows) { listKodAndShemMatbea.Add(row["KodAndShemMatbea"].ToString()); listTeuraMatbea.Add(row["TeuraMatbea"].ToString()); } } if (ServiceUtil.IsValid(servRet)) { grdNiyar.SetDataSourceByServerReturn(servRet); dg.AutoGenerateColumns = false; dg.ColumnCount = 4; dg.DataSource = servRet.Value; DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn(); cb.DataSource = servRet.Value.DefaultView.ToTable(true, KodAndShemMatbea&); //foreach (var item in listKodAndShemMatbea) //{ // cb.Items.Add(item); //} cb.HeaderText = "מטבע בבנק"; cb.DisplayMember = "123"; cb.DataPropertyName = "KodAndShemMatbea"; cb.DisplayMember = "KodAndShemMatbea"; cb.ValueMember = "KodAndShemMatbea"; dg.Columns.Add(cb); }</pre>
any help we be appreciate!!!
这篇关于如何在DataGridViewComboBoxColumn中使用多个数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!