单击绘制的复选框

安迪·皮莱(Andy pillay)

我有一个列表视图,其中包含许多绘制的复选框。

当前,当我单击列表视图上的绘制复选框时,它要么单击该列中的第一个复选框,要么完全不单击。

我知道这与温度点有关,因此,希望将其发布后,我可以自己解决问题,然后再回答:P。

这是绘制复选框的地方

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

这就是点击事件发生的地方

private void lstSourceToUser_MouseClick(object sender, MouseEventArgs e)
{
    ListViewItem.ListViewSubItem subItem = lstSourceToUser.HitTest(e.X, e.Y).SubItem;
    if (subItem.Name != "")
    {
        Point tempPoint = new Point(e.X, e.Y);
        int userIndex = userProfile.GetUserIndexByName(subItem.Name);
        Rectangle rect = new Rectangle(subItem.Bounds.X, subItem.Bounds.Y, 100, subItem.Bounds.Height);
        if (rect.Contains(tempPoint))
        {
            int srcIndex = userProfile.GetUserSourceIndexByUserName(subItem.Name, lstSourceToUser.SelectedItems[0].SubItems[0].Text);
            userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState = !userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState;
            this.lstSourceToUser.Invalidate();
        }
    }
}

任何帮助将不胜感激,无论是解决方案或链接/指南:)谢谢

安迪·皮莱(Andy pillay)

问题不是tempPoint,而是srcIndex。

if (rect.Contains(tempPoint))
    {
        **int srcIndex = userProfile.GetUserSourceIndexByUserName(subItem.Name, lstSourceToUser.SelectedItems[0].SubItems[0].Text);**
        userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState = !userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState;
        this.lstSourceToUser.Invalidate();
    }

public int GetUserSourceIndexByUserName(string userName, string sourceId)
    {
        foreach (FCMUser user in SystemUserList)
        {
            if (**user.id** != userName) continue;
            var index = 0;
            foreach (FCMSource src in user.fusionUserSources)
            {
                if (src.id == sourceId)
                {
                    return index;
                }
                index++;
            }
        }
        return 0;
    }

查找匹配的userName的if语句不正确。它正在检查用户ID,而不是用户名。

来自我的愚蠢的错误。我想生活和学习。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章