开发者

Infragistics Ultragrid - Combobox as column

开发者 https://www.devze.com 2023-04-02 05:35 出处:网络
I have a problem with the UltraGrid control from Infragistics. I have created a ultracombobox with a few values in it:

I have a problem with the UltraGrid control from Infragistics. I have created a ultracombobox with a few values in it:

 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. 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 u开发者_Python百科gc = 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. 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.

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:

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:
ultraComboPaneel.BindingContext = this.BindingContext;

Please note that setting binging context should happen prior setting your control to be EditorControl. 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. 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.

dim udd As UltraDropDown

udd = New 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消