4

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

//代码

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

我怎样才能做到这一点?

4

3 回答 3

7

在 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;                                   

    }

您的超组合将仅填充“ID”的值成员和“名称”的显示成员..

于 2014-04-04T10:09:52.087 回答
2

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

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

于 2013-05-31T13:16:19.687 回答
0

这是一个扩展方法,它将隐藏除列之外的所有列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
于 2017-12-13T18:07:47.620 回答