English 中文(简体)
如何在清单Box中展示理论
原标题:
  • 时间:2009-05-19 22:05:17
  •  标签:

I m 试图从假肢到名单Box展示钥匙/Value Pairs。

Key Value
A    10
B    20
C    30

我想以以下格式在清单Box中展示这些内容。

A(10)
B(20)
C(30)

采用以下代码,我得以将清单箱连接起来。 数据来源于理论。

myListBox.DataSource = new BindingSource(myDictionary, null);

展示

[A, 10]
[B, 20]
[C, 30]

我可以说明如何加以编排,以便以我所希望的方式展示。

任何帮助都将受到赞赏。

Thanks Ashish

最佳回答

3. 清单箱中的格式活动:

KeyValuePair<string, int> item = (KeyValuePair<string, int>)e.ListItem;
e.Value = string.Format("{0}({1})", item.Key, item.Value);
问题回答

适当长期的灵活性 我将尝试并使用一类物体,然后,你可以做你后来喜欢做的事情,提出事件,改变价值观,而不是使用独特的钥匙,从清单箱中获取真正的物体,而不是仅仅通过形式加以扼制。

public partial class tester : Form
{
    public tester()
    {
        InitializeComponent();
         List<MyObject> myObjects = new List<MyObject>();
        MyObject testObject = new MyObject("A", "10");
        myObjects.Add(testObject);
       BindingSource bindingSource = new BindingSource(myObjects,null);
        listBox1.DisplayMember = "DisplayValue";
        listBox1.DataSource = bindingSource;
    }
}

public  class MyObject
{
    private string _key;
    private string _value;

    public MyObject(string value, string key)
    {
        _value = value;
        _key = key;
    }

    public string Key
    {
        get { return _key; }
    }

    public string Value
    {
        get { return _value; }
    }

    public string DisplayValue
    {
        get { return string.Format("{0} ({1})", _key, _value); }
    }
}

您可以重复字典标语,并在你到场时建立名单箱。

  foreach (KeyValuePair<string, int> kvp in myDictionary)
  {
      lbx.Items.Add(String.Format("{0}({1})", kvp.Key, kvp.Value.ToString()));
  }

实际上,如果你希望定制名单箱,从中取出,倒置。

答复1将获得你在问题中所陈述的内容,但如果你想反映目标的变化,那么如果你写照例行的绘画,那将更好。

或 您 也将如此之多的项目案文。

Don tabes,et BeginUpdate() and EndUpdate()





相关问题
热门标签