【问题标题】:Error with Dictionary Object: The name 'LotMaterialList' does not exist in the current context字典对象错误:当前上下文中不存在名称“LotMaterialList”
【发布时间】:2013-08-28 03:29:04
【问题描述】:

我有一个这样声明的字典对象:

Dictionary<string, string> LotMaterialList = new Dictionary<string, string>();

我稍后会像这样填充一个组合框:

cbxMaterials.ItemsSource = LotMaterialList;
cbxMaterials.DisplayMemberPath = "Value";
cbxMaterials.SelectedValuePath = "Key";

这工作正常。我将它放在面板上的弹出窗口中,并正确显示所有信息。在组合框的选择更改上,我有以下代码:

if (null != cbxMaterials.SelectedValue)  
{  
  CreateEditMaterial.materialId = cbxMaterials.SelectedValue.ToString();  
  CreateEditMaterial.materialDesc = LotMaterialList(CreateEditMaterial.materialId);  
}   

LotMaterialList 给了我The name 'LotMaterialList' does not exist in the current context 的错误,我之前做过这个没有问题,将我当时的做法与这个进行比较,我无法发现任何差异。所以我猜我错过了一些非常简单的东西。

建议?

谢谢

【问题讨论】:

  • LotMaterialList 声明在哪里?你能发布你的完整代码吗?
  • 这看起来不对:= LotMaterialList(CreateEditMaterial.materialId);。你的意思是把它放在括号里,像这样吗? = LotMaterialList[CreateEditMaterial.materialId];
  • @Gjeltema 是的,就像我说的那样简单......如果长时间编码,则需要更多咖啡。谢谢它现在正在工作。
  • 酷 - 作为答案发布,因此可以关闭此问题。

标签: c# wpf dictionary


【解决方案1】:

您使用() 而不是[] 来访问您的Dictionary

替换:

CreateEditMaterial.materialDesc = LotMaterialList(CreateEditMaterial.materialId);

CreateEditMaterial.materialDesc = LotMaterialList[CreateEditMaterial.materialId];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-01
    • 2010-12-17
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多