简体   繁体   English

Infragistics Ultragrid valueList / UltraDropDown

[英]Infragistics Ultragrid valueList/UltraDropDown

What event to I need to handle to allow users to add "fruit" the either a valuelist or ultra dropdown. 我需要处理什么事件,以允许用户在值列表或超级下拉列表中添加“水果”。

Since it is a KVP I always get format exception 由于它是KVP,所以我总是会遇到格式异常

Dictionary<int,string> fruits = new Dictionary<int,string>();



 private void FruitInit()
     {
    //Create some fruit        
    fruits.Add(-1,"apple");
            fruits.Add(-2,"banana");

            //Create and add to the ultraDropDown
            UltraDropDown fruitUltraDropDown = new UltraDropDown();
            fruitUltraDropDown.DataSource = fruits.ToList();
            fruitUltraDropDown.DisplayMember = "Value";
            fruitUltraDropDown.ValueMember = "Key";
            MyUltraGrid.DisplayLayout.Bands[0].Columns["MyColumn"].ValueList = fruitUltraDropDown;
        }

What event can I handle so when a user types "grape" I can add it to the dictionary with my own key, and it gets added to the dropdownlist. 我可以处理什么事件,所以当用户键入“ grape”时,可以使用自己的键将其添加到字典中,然后将其添加到下拉列表中。 Currently if I type "grape in the cell, I just get a format exception. 目前,如果我在单元格中键入“ grape”,则只会收到格式异常。

Regards 问候

_Eric _Eric

Got a response from Mike@infragistics, I didn't know about ValueListResolved 得到了回应迈克@infragistics,我不知道ValueListResolved

Answer from Mike 迈克的回答

There are a number of events you could use. 您可以使用许多事件。 I would probably use BeforeCellUpdate or maybe BeforeExitEditMode. 我可能会使用BeforeCellUpdate或BeforeExitEditMode。

Either way, what you would do is use the ValueListResolved property on the cell to get the ValueList and then you can use the GetValue method to try to find a matching item on the list. 无论哪种方式,您都将使用单元格上的ValueListResolved属性来获取ValueList,然后可以使用GetValue方法尝试在列表上查找匹配项。 Use the cell.EditorResolved.Text to get the current edit text in the cell for your search. 使用cell.EditorResolved.Text来获取单元格中用于编辑的当前编辑文本。

If you use an "UltraDropDown" for the value list, you can handle it's "BeforeDropDown" event. 如果将“ UltraDropDown”用于值列表,则可以处理其“ BeforeDropDown”事件。 Compare the "used" values in the grid to the values in the UltraDropDown, then hide the ones that are in use. 将网格中的“已使用”值与UltraDropDown中的值进行比较,然后隐藏正在使用的值。 Worked for me. 为我工作。

    private void BindApprovalsTab()
    {
        uddApproverList.BeforeDropDown -= new CancelEventHandler(uddApproverList_BeforeDropDown);
        uddApproverList.DataSource = dsFindingDetails.Tables["Approvers"];
        uddApproverList.DisplayMember = "fldDisplayName";
        uddApproverList.ValueMember = "fldRoleGID";
        uddApproverList.Width = 150;
        uddApproverList.DisplayLayout.Bands[0].Columns["fldRoleGID"].Hidden = true;
        uddApproverList.DisplayLayout.Bands[0].Columns["fldDisplayName"].Header.Caption = "Role";
        uddApproverList.DisplayLayout.Bands[0].Columns["fldDisplayName"].Width = uddApproverList.Width;
        uddApproverList.BeforeDropDown += new CancelEventHandler(uddApproverList_BeforeDropDown);

        ugActionItemApprovals.DataSource = dsFindingDetails.Tables["tblIssueApprovals"];

    }

    void uddApproverList_BeforeDropDown(object sender, CancelEventArgs e)
    {
        //assume all rows show
        foreach (UltraGridRow udr in uddApproverList.Rows)
        {
            udr.Hidden = false;
        }
        //can we remove already used entries?
        foreach (UltraGridRow udr in uddApproverList.Rows)
        {
            string sDDRoleGID = udr.Cells["fldRoleGID"].Value.ToString();
            foreach (UltraGridRow ur in ugActionItemApprovals.Rows)
            {
                if (ur.Cells["fldApprovalRequiredBy"].Value.ToString() == sDDRoleGID)
                {
                    udr.Hidden = true;
                    break;
                }
            }
        }
    }

This may or may not be relevant to your question, but there are many strange things in your code. 这可能与您的问题无关,但可能与您的问题无关,但是代码中有很多奇怪的事情。

UltraDropDown fruitUltraDropDown = new UltraDropDown();

Infragistics includes wizards to create, populate, and display controls in the designer.cs file. Infragistics包括用于在designer.cs文件中创建,填充和显示控件的向导。 Instantiating a control like this throws away all the designer data and creates a new, default control. 实例化这样的控件会丢弃所有设计器数据,并创建一个新的默认控件。 Do you really intend this? 你真的打算吗? Is this an excerpt from the designer.cs file? 这是来自designer.cs文件的摘录吗?

fruitUltraDropDown.DataSource = fruits.ToList();

This creates a new List<KeyValuePair<int, string>> from your Dictionary . 这将从您的Dictionary创建一个新的List<KeyValuePair<int, string>> fruits is now unreachable and eligible for garbage collection, any change made to it will never be propagated to fruitUltraDropDown . 现在, fruits无法访问并且可以进行垃圾回收,对其所做的任何更改都永远不会传播到fruitUltraDropDown Why are you creating fruits only to throw it away? 为什么要制造fruits只是为了扔掉它?

What event can I handle so when a user types "grape"... 当用户键入“ grape”时,我可以处理什么事件...

Types where? 类型在哪里? fruitUltraDropDown ? fruitUltraDropDown The designer data has been thrown away so fruitUltraDropDown is not editable, unless there is a lot of code you are not showing. 设计器数据已被丢弃,因此fruitUltraDropDown是不可编辑的,除非您没有显示很多代码。 MyUltraGrid ? MyUltraGrid You do not show any code for this, so no one can have any idea what it implements. 您没有为此显示任何代码,因此没有人知道它实现了什么。 A text field? 文本字段? Programmatic data? 程序化数据? A total mystery. 完全是个谜。

I can add it to the dictionary... 我可以将它添加到字典中。

Adding anything to Dictionary is pointless because you no longer use it. Dictionary添加任何内容都是没有意义的,因为您不再使用它。 If you want to add it to ultraDropDown1.DataSource you have to add a KeyValuePair<int, string> : 如果要将其添加到ultraDropDown1.DataSource ,则必须添加一个KeyValuePair<int, string>

var ds = ultraDropDown1.DataSource as List<KeyValuePair<int, string>>;
ds.Add(new KeyValuePair<int,string>(-3, "grape"));

This will just add the entry to the backing store. 这只会将条目添加到后备存储中。 If you want to include it in ultraDropDown1 : 如果要将其包含在ultraDropDown1

ultraDropDown1.DataBind();

If this is not helpful you must add enough information to your question so that someone without your source code can understand what you are trying to do. 如果这没有帮助,则必须在问题中添加足够的信息,以便没有源代码的人可以理解您要执行的操作。

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

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