复选框将多个值设为true

时间:2016-06-01 10:44:59

标签: c# xml winforms checkbox boolean

我已经被困了一段时间,并且会喜欢一些见解。

当我添加新用户或源并检查绘制的复选框时,它会在检查时使bool为true,如预期的那样。

但是,它还会将连接到该源的所有其他用户检查为true或false。

[前]

[1]

[后]

[2]

仅当我将XML文件加载到已有现有数据的程序中,然后通过UI添加新的用户或来源时才会出现这种情况。

这是LoadXML方法的一部分。

// Load the source list
        sourceProps.SystemSources.Clear();
        fCMUserSourceBindingSource.Clear();
        fCMSourceBindingSource.Clear();

        foreach (FusionSource src in fusionSystem.sourceList)
        {
            FCMSource fSource = new FCMSource(src);
            sourceProps.SystemSources.Add(fSource);
            fCMSourceBindingSource.Add(fSource);
            fCMUserSourceBindingSource.Add(fSource);
        }
        txtSourceID.Text = sourceProps.GenerateNextSourceId();

        // Load the user data from the fusionSystem object.
        userProfile.SystemUserList.Clear();

        //currently clears grid. might need to clear list instead
        fCMUserBindingSource.Clear();

        foreach (FusionUser usr in fusionSystem.userList)
        {
            FCMUser fUser = new FCMUser(usr);
            userProfile.SystemUserList.Add(fUser);
            fCMUserBindingSource.Add(fUser);

            foreach (FusionSourcePermission srcPerm in usr.SourcePermissionList)
            {
                FCMSource fSource = new FCMSource(srcPerm);
                fUser.fusionUserSources.Add(fSource);
            }
        }
        AddColumnsUsersToSourceAllocation();
        txtUserID.Text = userProfile.GenerateNextUserId();

        // Load the zone group data from the fusionSystem object
        zoneProps.systemZoneGroupList.Clear();
        fCMZoneGroupBindingSource.Clear();

任何帮助将不胜感激。

修改

ListView没有绑定,所有'检查'用户激活点击事件时以编程方式完成。

private void lstSourceToUser_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
    {
        if (e.ColumnIndex > 1)
        {
            int usrIndex = userProfile.GetUserIndexByID(e.Header.Name);
            int srcIndex = userProfile.GetUsersSourceIndex(e.Header.Name, e.Item.SubItems[0].Text);
            Graphics g = e.Graphics;
            CheckBoxRenderer.DrawCheckBox(g,new Point((e.Bounds.X + e.Bounds.Width/2 -10 ),(e.Bounds.Y)), userProfile.SystemUserList[usrIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
        }
        else
            // Draw the other subitems with default drawing.
            e.DrawDefault = true;
    }

修改

这是FCMSource构造函数。

        public FCMSource(string sourceId, string sourceName, string icnId, string lstIndx)
    {
        id = sourceId;
        icon = icnId;
        name = sourceName;
        listIndex = lstIndx;
        UserSourceCheckState = false;
        UserSourceChkBox = new MyCheckBoxItem(false);
    }

    public FCMSource(FCMSource fSource, bool chk)
    {
        name = fSource.name;
        icon = fSource.icon;
        id = fSource.id;
        listIndex = fSource.listIndex;
        UserSourceCheckState = chk ? true : false;
        UserSourceChkBox = new MyCheckBoxItem(chk);
    }

这是包含不同Sources的FCMUser构造函数。

 public FCMUser(string userid, string nm, string icn, string pinNo, CheckBox pinEn, string lstIndx)
    {
        id = userid;
        name = nm;
        icon = icn;
        pin = pinNo;
        pinEnabled = pinEn.CheckState;
        chkBoxPINEnable = new MyCheckBoxItem(false);
        fusionUserSources = new List<FCMSource>();
        ListIndex = lstIndx;
        updateCheckbox();
    }

0 个答案:

没有答案