Question

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

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. Currently if I type "grape in the cell, I just get a format exception.

Regards

_Eric

Was it helpful?

Solution

Got a response from Mike@infragistics, I didn't know about ValueListResolved

Answer from Mike

There are a number of events you could use. I would probably use BeforeCellUpdate or maybe 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. Use the cell.EditorResolved.Text to get the current edit text in the cell for your search.

OTHER TIPS

If you use an "UltraDropDown" for the value list, you can handle it's "BeforeDropDown" event. Compare the "used" values in the grid to the values in the UltraDropDown, then hide the ones that are in use. 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. 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?

fruitUltraDropDown.DataSource = fruits.ToList();

This creates a new List<KeyValuePair<int, string>> from your Dictionary. fruits is now unreachable and eligible for garbage collection, any change made to it will never be propagated to fruitUltraDropDown. Why are you creating fruits only to throw it away?

What event can I handle so when a user types "grape"...

Types where? fruitUltraDropDown? The designer data has been thrown away so fruitUltraDropDown is not editable, unless there is a lot of code you are not showing. 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. If you want to add it to ultraDropDown1.DataSource you have to add a 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.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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top