已检查组合框问题 [英] Checked combo box issue

查看:46
本文介绍了已检查组合框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个选中的组合框..

第一个将包含枚举(BSECash,NSECash)...第二个将根据第一个中的枚举的选择填充枚举名称..
公开枚举BSECash
滚动= 1
T2T = 2
拍卖= 3
瓦兰= 4
Close_Out = 5
开幕= 6
Corp_Act = 7
结束枚举
公开枚举NSECash
正常= 1
TFT = 2
Auction_Normal = 3
Close_Out = 4
开场= 5
Corp_Act = 6
结束枚举
问题是..假设是否我选择BSECash并检查第二个项目中的某些项目...后来,当我检查NSEcash时,第二个项目中所有以前的已检查项目都变得未选中..

Hi,
I have two checked combo boxes..

First one will Consist of enums (BSECash,NSECash)...second will filled with enum names according to the selection of enums in first one...enums are..
Public Enum BSECash
Rolling = 1
T2T = 2
Auction = 3
Valan = 4
Close_Out = 5
Opening = 6
Corp_Act = 7
End Enum
Public Enum NSECash
Normal = 1
TFT = 2
Auction_Normal = 3
Close_Out = 4
Opening = 5
Corp_Act = 6
End Enum
issue is..suppose if i select BSECash and i check some of items in the second one...and later when i check NSEcash all previous checked items in the second one are becoming unchecked..

Private Sub ccmbExchngeSegment_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ccmbExchngeSegment.SelectedIndexChanged, ccmbExchngeSegment.SelectedValueChanged, ccmbExchngeSegment.TextChanged
       Try
           ccmbSettlementType.Items.Clear()
           For iCnt As Int32 = 0 To ccmbExchngeSegment.CheckedItems.Count - 1
               If ccmbExchngeSegment.CheckedItems.Item(iCnt).ToString = "BSECash" Then
                  Dim iCntn As Int32 = [Enum].GetNames(GetType(BSECash)).Length
                 For jCnt As Int32 = 1 To iCntn
                       ccmbSettlementType.Items.Add(New clsValDescPair(jCnt, CType(jCnt, BSECash).ToString.Replace("_", " ")))
                   Next
                 ElseIf ccmbExchngeSegment.CheckedItems.Item(iCnt).ToString = "NSECash" Then
              Dim iCntn As Int32 = [Enum].GetNames(GetType(NSECash)).Length
                   For jCnt As Int32 = 1 To iCntn
                       ccmbSettlementType.Items.Add(New clsValDescPair(jCnt, CType(jCnt, NSECash).ToString.Replace("_", " ")))
                   Next
               End If

           Next



逻辑缺少某些地方...帮助我..



logic is missing some where...help me out..

推荐答案

导致项目变为未选中状态的答案是,每当您在第一次检查中选择另一个枚举时框中,清除所有项目,然后重新添加它们.这意味着您删除了所有内容并添加了新内容,因此之前检查过的所有记录都将丢失.为了解决这个问题,您必须做一些比每次刷新列表都要复杂的事情.我认为以下方法可以解决您的问题(伪代码和实代码的混合):

The answer to why the items are becoming unchecked is that whenever you select another enum in your first check box, you clear all the items then re-add them. This means that you remove everything and add new ones so there all record of what was checked before is lost. To solve this you must do something a bit more sophisticated than just refresh your list each time. I think the following ought to solve your problem (mix of pseudo code and real code):

Dictionary of <enum,>> SelectedItems
Enum PreviouslySelectedEnum = null
Method  ccmbExchngeSegment_SelectedIndexChanged

    IF NOT PreviouslySelectedEnum = null 
        IF NOT SelectedItems contains key PreviouslySelectedEnum
            SelectedItems.Add(PreviouslySelectedEnum, new List<string>())
        END IF
        
        SelectedItems[PreviouslySelectedEnum].Clear()
        FOR i = 0 to ccmbSettlementType.Items.Count
            IF ccmbSettlementType.Items[i].Checked
                SelectedItems[PreviouslySelectedEnum].Add(ccmbSettlementType.Items[i].Text)
            END IF
        END FOR
    END IF

    NewSelectedEnum = ccmbExchngeSegment.Items[ccmbExchngeSegment.SelectedIndex]
    ccmbSettlementType.Items.Clear()
    For iCnt As Int32 = 0 To ccmbExchngeSegment.CheckedItems.Count - 1
        If ccmbExchngeSegment.CheckedItems.Item(iCnt).ToString = "BSECash" Then
            Dim iCntn As Int32 = [Enum].GetNames(GetType(BSECash)).Length
            For jCnt As Int32 = 1 To iCntn
                ccmbSettlementType.Items.Add(New clsValDescPair(jCnt, CType(jCnt, BSECash).ToString.Replace("_", " ")))
            Next
        ElseIf ccmbExchngeSegment.CheckedItems.Item(iCnt).ToString = "NSECash" Then
            Dim iCntn As Int32 = [Enum].GetNames(GetType(NSECash)).Length
            For jCnt As Int32 = 1 To iCntn
                ccmbSettlementType.Items.Add(New clsValDescPair(jCnt, CType(jCnt, NSECash).ToString.Replace("_", " ")))
            Next
        End If     
     Next

     IF SelectedItems contains key NewSelectedEnum
        FOR EACH String ASelectedItem in  SelectedItems[NewSelectedEnum]
            ComboBoxItem TheItem = Get combo box item where ASelectedItem = TheComboBoxItem.Text
            TheItem.Checked = true
        END FOR
     END IF
     
     PrevouslySelectedEnum = NewSelectedEnum     
End Method
</string>



此代码基本上保存在SelectedItems列出所有曾经得到选中,那么当选择的指数的变化,重新选择任何在该列表中枚举.尽管我已经复制了您需要的原始代码,但这不是正确的VB代码.在以后编写的任何代码中,要获取选定的枚举列表,只需使用SelectedItems列表,然后将Strings转换为实际的枚举值(使用Enum.Parse).

希望这会有所帮助,
Ed



This code basically saves in the SelectedItems list all the enums that ever get checked then when the selected index changes, reselects any that are in that list. This is not proper VB code though I have copied in your original code which you will need. In any code you write later, to get the list of enums that were selected just use the SelectedItems list and convert the Strings into actual enum values (using Enum.Parse).

Hope this helps,
Ed


这篇关于已检查组合框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆