简体   繁体   English

Infragistics Ultragrid - Combobox作为专栏

[英]Infragistics Ultragrid - Combobox as column

I have a problem with the UltraGrid control from Infragistics. 我对Infragistics的UltraGrid控件有疑问。 I have created a ultracombobox with a few values in it: 我创建了一个带有一些值的ultracombobox:

 UltraCombo ultraComboPaneel = new UltraCombo();
        ultraComboPaneel.DataSource = articleList;
        ultraComboPaneel.ValueMember = "ArticleID";
        ultraComboPaneel.DisplayMember = "Name";

Now I have an UltraGrid, and I want to put the ultraCombo in a cell so I can choose one of the items of the ultracombo as a cell value. 现在我有一个UltraGrid,我想将ultraCombo放在一个单元格中,这样我就可以选择ultracombo中的一个项目作为单元格值。 I tried it both in code and in the ultragrid designer but i can't seem to find a way to do it. 我在代码和超网格设计器中都尝试过,但我似乎找不到办法。

Any of you got an idea? 你们中有人有个主意吗? More information can be provided if needed 如果需要,可以提供更多信息

Edit: 编辑:

I found something like 我发现了类似的东西

UltraGridColumn ugc = ultraGridTypePaneel.DisplayLayout.Bands[0].Columns.Add("combo");
ultraGridTypePaneel.DisplayLayout.Bands[0].Columns["combo"].EditorControl = ultraComboPaneel;

I feel I'm on the right way but it is still not showing on the screen... 我觉得我的方式正确,但屏幕上还没有显示...

The UltraCombo provides a great deal of functionality. UltraCombo提供了大量功能。 If all you need is the ability to choose an item from a list, you might find the grid's ValueLists provide a better solution. 如果您只需要从列表中选择项目,您可能会发现网格的ValueLists提供了更好的解决方案。

Here's some code to get you started: 这里有一些代码可以帮助您入门:

    private void myGrid_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
    {
        const string colorValueList = @"ColorValueList";

        if (!e.Layout.ValueLists.Exists(colorValueList))
        {
            ValueList svl = e.Layout.ValueLists.Add(colorValueList);
            svl.ValueListItems.Add(1, "Red");
            svl.ValueListItems.Add(2, "Green");
            svl.ValueListItems.Add(3, "Blue");
        }
        e.Layout.Bands[0].Columns["Color"].ValueList = e.Layout.ValueLists[colorValueList];
    }

You could find at the link below some approaches that you could use to put a DropDown into a UltraGrid cell: 您可以在下面的链接中找到一些可用于将DropDown放入UltraGrid单元格的方法:

http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7841 http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7841

Going back to your current code snippet - you are almost there: 回到你当前的代码片段 - 你几乎就在那里:

First you should set the binding context of your UltraCombo to the BindingContext of the form the your UltraCombo will be used like: 首先,您应该将UltraCombo的绑定上下文设置为UltraCombo将使用的表单的BindingContext,如:
ultraComboPaneel.BindingContext = this.BindingContext;

Please note that setting binging context should happen prior setting your control to be EditorControl. 请注意,在将控件设置为EditorControl之前,应该设置binging上下文。 One more thing that I noticed is that the property currently is changed to EditorComponent so I believe that you are using older version of the Infragistics components. 我注意到的另一件事是该属性当前已更改为EditorComponent,因此我相信您使用的是旧版本的Infragistics组件。 However you should still be able to use the very same approach. 但是,您仍然可以使用相同的方法。 I have created small code snippet showing the above with code: 我创建了一个小代码片段,显示上面的代码:

public partial class Form1 : Form
{
    UltraCombo uc;
    public Form1()
    {
        InitializeComponent();
        DataTable dt = new DataTable();
        dt.Columns.Add("Int", typeof(int));
        dt.Rows.Add(1);
        dt.Rows.Add(1);
        dt.Rows.Add(1);

        DataTable dtt = new DataTable();
        dtt.Columns.Add("Int", typeof(int));
        dtt.Rows.Add(2);
        dtt.Rows.Add(2);
        dtt.Rows.Add(2);

        uc = new UltraCombo();
        uc.BindingContext = this.BindingContext;
        uc.DataSource = dtt;

        ultraGrid1.DataSource = dt.DefaultView;
    }

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
    {
        e.Layout.Bands[0].Columns[0].EditorComponent = uc;
    }
}

Hope this helps. 希望这可以帮助。

I use the Ultra Dropdown instead. 我使用的是Ultra Dropdown。

dim udd As UltraDropDown dim udd作为UltraDropDown

udd = New UltraDropDown udd =新的UltraDropDown

    With udd
        'add data binding or value list items here
    End With


    Me.ultragrid.DisplayLayout.Bands(0).Columns("Column Name").ValueList = udd

The key is the last line that assigns the "Value List" of the ultra grid column to the Drop down control. 关键是将超网格列的“值列表”分配给下拉控件的最后一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM