Infragistics Ultragrid valueList/UltraDropDown

发布于 2024-10-08 19:29:26 字数 820 浏览 14 评论 0 原文

我需要处理什么事件才能允许用户在值列表或超级下拉列表中添加“水果”。

由于它是 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;
        }

我可以处理什么事件,因此当用户输入“grape”时,我可以使用自己的密钥将其添加到字典中,并将其添加到下拉列表中。目前,如果我在单元格中输入“grape”,我只会收到格式异常。

问候

_Eric

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纸伞微斜 2024-10-15 19:29:26

收到 Mike@infragistics 的回复,我不知道 ValueListResolved

来自的回答迈克

您可以参加许多活动
使用。我可能会用
BeforeCellUpdate 或者也许
退出编辑模式之前。

无论哪种方式,你要做的就是使用
ValueListResolved 属性
单元格来获取 ValueList 然后你
可以使用GetValue方法尝试
在列表中找到匹配的项目。使用
要获取的 cell.EditorResolved.Text
单元格中当前编辑的文本
您的搜索。

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.

メ斷腸人バ 2024-10-15 19:29:26

如果您对值列表使用“UltraDropDown”,则可以处理它的“BeforeDropDown”事件。将网格中的“已使用”值与 UltraDropDown 中的值进行比较,然后隐藏正在使用的值。
为我工作。

    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;
                }
            }
        }
    }

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;
                }
            }
        }
    }
我们的影子 2024-10-15 19:29:26

这可能与您的问题相关,也可能不相关,但是您的代码中有很多奇怪的事情。

UltraDropDown fruitUltraDropDown = new UltraDropDown();

Infragistics 包括用于在 Designer.cs 文件中创建、填充和显示控件的向导。像这样实例化一个控件会丢弃所有设计器数据并创建一个新的默认控件。你真的有意这样做吗?这是 Designer.cs 文件的摘录吗?

fruitUltraDropDown.DataSource = fruits.ToList();

这将从您的 Dictionary 中创建一个新的 List>fruits 现在无法访问并且符合垃圾回收条件,对其所做的任何更改都不会传播到 fruitUltraDropDown。为什么你创造水果只是为了扔掉它?

当用户键入“grape”时,我可以处理什么事件...

在哪里键入? fruitUltraDropDown?设计器数据已被丢弃,因此 fruitUltraDropDown 不可编辑,除非有大量代码未显示。 MyUltraGrid?您没有为此显示任何代码,因此没有人知道它实现了什么。文本字段?程序化数据?完全是个谜。

我可以将它添加到字典中...

Dictionary 添加任何内容都是毫无意义的,因为您不再使用它。如果您想将其添加到 ultraDropDown1.DataSource 中,则必须添加一个 KeyValuePair

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

这只会将条目添加到后备存储中。如果您想将其包含在 ultraDropDown1 中:

ultraDropDown1.DataBind();

如果这没有帮助,您必须向您的问题添加足够的信息,以便没有您的源代码的人能够理解您正在尝试执行的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文