【问题标题】:Windows Form Combobox SelecteditemWindows 窗体组合框 Selecteditem
【发布时间】:2013-03-25 09:42:19
【问题描述】:

在列表视图行中编辑特定记录时,如何将该值获取到相应的组合框选定项/值?

组合框处于下拉列表样式模式,因此所选文本将不起作用。

我试过这个:

cbBrand.SelectedItem = lvMain.SelectedItems[0].SubItems[1].ToString();

但我在相应的组合框选定项中得到null... :(

【问题讨论】:

  • 如果你不'.ToString()'子项怎么办?
  • @Seb cbBrand.SelectedValue = lvMain.SelectedItems[0].SubItems[1];让我无法将“ListViewSubItem”类型的对象转换为“System.IConvertible”
  • 我要的是.SelectedItem而不是.SelectedValue
  • @Seb 没有任何反应.. 因为它正在传递一个值... ComboBox 的配置如下: cb.DataSource = dt; cb.DisplayMember = "名称"; cb.ValueMember = "id";所以它期待一个值,我认为它是名称..

标签: c# combobox windows-forms-designer


【解决方案1】:

我是这样工作的:

int xcb;
xcb = this.cbBrand.FindString(lvMain.SelectedItems[0].SubItems[1].Text);
this.cbBrand.SelectedIndex = xcb;

【讨论】:

    【解决方案2】:

    您可以使用 SelectedValue 属性。

    【讨论】:

    • cbBrand.SelectedValue = lvMain.SelectedItems[0].SubItems[1].ToString();让我输入字符串的格式不正确。
    • cbBrand.SelectedValue = lvMain.SelectedItems[0].SubItems[1];让我无法将“ListViewSubItem”类型的对象转换为“System.IConvertible”类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2015-09-12
    • 1970-01-01
    相关资源
    最近更新 更多