Dropdown should show only the display member

主宰稳场 提交于 2019-12-01 18:48:55

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.

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

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

    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..

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

<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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!