vb.net 下拉列表应仅显示显示成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16854159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:48:34  来源:igfitidea点击:

Dropdown should show only the display member

vb.netcomboboxinfragistics

提问by iamCR

I have bound a collection to ultracomboand I have specified the value memberand display member. The collections have many columns, Now I have to show only one column in that in display and one column assigned to value member. Now i'm seeing all the columnsin the collections are getting displayed as multicolumn.

我已经绑定了一个集合ultracombo并指定了value memberand display member。集合有很多列,现在我必须在显示中只显示一列,并将一列分配给value member. 现在我看到columns集合中的所有内容都显示为multicolumn.

//Code

//代码

 cboUltra.ValueMember = "LookupValue"
 cboUltra.DisplayMember = "LookupValueDescription"
 cboUltra.DataSource = LoadLookupDetails(Field.LookUpCode)
 UltraGridRow.Cells("FieldValue").ValueList = cboUltra

How can I achieve that?

我怎样才能做到这一点?

采纳答案by alhalama

The UltraCombo will generate all of the columns automatically. You could either add the column you want before setting the data source and set cboUltra.DisplayLayout.NewColumnLoadStyle to NewColumnLoadStyle.Hide or you could hide all of the columns except the one you want after they are created by looping through them in the InitializeLayout event and setting them all to hidden except the one that you want.

UltraCombo 将自动生成所有列。您可以在设置数据源之前添加您想要的列并将 cboUltra.DisplayLayout.NewColumnLoadStyle 设置为 NewColumnLoadStyle.Hide 或者您可以隐藏除您想要的列之外的所有列,通过在 InitializeLayout 事件中循环遍历它们,将它们全部设置为隐藏,除了您想要的那个。

You could also look at the UltraComboEditoras that only displays a single column. Whether this is an options for you will depend on what features you need in your drop down.

您还可以查看UltraComboEditor,因为它只显示一列。这是否适合您将取决于您在下拉列表中需要哪些功能。

回答by Sagar Dev Timilsina

In C# you can try the following: --> Add "ultraCombo1" as you ultra combo... on form load try following code:

在 C# 中,您可以尝试以下操作:--> 在超组合时添加“ultraCombo1”... 在表单加载时尝试以下代码:

    private void Form1_Load(object sender, EventArgs e)
    {
        // Fill data in ultracombo datasource
        DataTable dtt = new DataTable();
        dtt.Columns.Add("ID", typeof(int));
        dtt.Columns.Add("Name", typeof(string));
        dtt.Columns.Add("Age", typeof(int));
        dtt.Columns.Add("Address", typeof(string));
        dtt.Columns.Add("Sex", typeof(string));
        dtt.Rows.Add(new object[] {1,"Name1",20,"Address 1","Male"});
        dtt.Rows.Add(new object[] { 2, "Name2", 21, "Address 2", "Male" });
        dtt.Rows.Add(new object[] { 3, "Name3", 22, "Address 3", "Female" });
        dtt.Rows.Add(new object[] { 4, "Name4", 23, "Address 4", "Male" });
        dtt.Rows.Add(new object[] { 5, "Name5", 24, "Address 5", "Female" });
        ultraCombo1.DataSource = dtt;
        ultraCombo1.DataBind();
        //---------------------------------

        // hide all but show "ID" and "Name" only

        ultraCombo1.ValueMember = "ID";
        ultraCombo1.DisplayMember = "Name";
        for (int i = 0; i < ultraCombo1.Rows.Band.Columns.Count; i++)
        {
            ultraCombo1.Rows.Band.Columns[i].Hidden = true;
        }
        ultraCombo1.Rows.Band.Columns["ID"].Hidden = false;
        ultraCombo1.Rows.Band.Columns["Name"].Hidden =  false;                                   

    }

Your ultracombo will be populated with value member of "ID" and displaymember of "Name" only..

您的 Ultracombo 将仅填充“ID”的值成员和“名称”的显示成员。

回答by Walter Stabosz

Here is an extension method that will hide all columns besides the DisplayMembercolumn.

这是一个扩展方法,它将隐藏除列之外的所有列DisplayMember

<Extension()>
Public Sub ShowOnlyDisplayMemberColumn(this As UltraCombo)
    Dim columnName As String = this.DisplayMember
    For Each band As UltraGridBand In this.DisplayLayout.Bands
        For i As Integer = 0 To band.Columns.Count - 1
            Dim column As UltraGridColumn = band.Columns(i)
            If (column.Key = columnName) Then
                column.Hidden = False
                column.Width = this.Width
            Else
                column.Hidden = True
            End If
        Next
    Next
End Sub