【问题标题】:populate a combobox from a dictionary <string, class>从字典 <string, class> 填充组合框
【发布时间】:2015-03-08 01:38:43
【问题描述】:

我想从字典中填充一个组合框,但我收到了 error of argument 2: cannot convert from 'int' to 'class'。该类是条形码阅读器。我应该怎么做?还有其他选择吗? 这是我想使用但不起作用的代码:

    private static Dictionary<string, BarcodeReader> CodeType =
           new Dictionary<string, BarcodeReader> 
                    {
                        {"Codabar", BarcodeReader.CODABAR},
                        {"Code 39", BarcodeReader.CODE39},
                    };
        // Populate cbobox
        cboCodeType.Items.AddRange(CodeType.Keys.ToArray());
        cboCodeType.SelectedIndex = 0;

【问题讨论】:

    标签: dictionary combobox populate


    【解决方案1】:

    这是因为 BarcodeReader.CODABARBarcodeReader.CODE39 是 int 值,而不是 BarcodeReader 的实例。尝试将 CodeType 字典的值类型更改为 int,如下所示:

    private static IDictionary<string, int> CodeType =
        new Dictionary<string, int> 
        {
            {"Codabar", BarcodeReader.CODABAR},
            {"Code 39", BarcodeReader.CODE39},
        };
    

    在我看来,该库没有提供任何检索 BarcodeReader 实例的方法,公共读取方法都接受 barcodeType 作为 int。

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2015-05-23
      • 2019-06-07
      • 1970-01-01
      • 2013-06-22
      • 2011-11-20
      相关资源
      最近更新 更多