简体   繁体   English

CheckedListBox填充文本控件

[英]CheckedListBox populating a text control

I have a text box that is going to be populated with a comma spereated list that is driven by a CheckedListBox control. 我有一个文本框,其中将填充一个由CheckedListBox控件驱动的逗号分隔的列表。

The idea is that as the user checks items off in the list, they will appear in the text field above. 其想法是,当用户在列表中选中项目时,它们将出现在上方的文本字段中。 I have this working to the point where if I check an item and then click somewhere else inside the control then the text ends up in the textbox. 我的工作到了这样的程度:如果我检查一个项目,然后在控件内的其他位置单击,则文本最终出现在文本框中。 I am capturing the click event on my control. 我正在捕获控件上的click事件。

If I use the item_checked event then the list in the text box isn't updated until I check a second item (at which point in time only the first item that was checked is displayed in the text box.) Is there anyway around this? 如果我使用item_checked事件,则在我检查第二个项目之前,文本框中的列表不会更新(此时,只有选中的第一个项目显示在文本框中)。 Reading on MSDN doesn't seem to show any other events that would be applicable. 在MSDN上阅读似乎没有显示任何其他适用的事件。

I'm using .net 1.1. 我正在使用.net 1.1。

This is the method that is run on the event trap. 这是在事件陷阱上运行的方法。

Private Sub FillCheckedTagsTextBox()

  txtSelectedTags.Text = "" Dim tagChecked As Object For Each tagChecked In cltTagSelection.CheckedItems txtSelectedTags.Text = txtSelectedTags.Text + tagChecked.ToString() + ", " Next End Sub 

txtSelectedTags.Text = "" Dim tagChecked As Object For Each tagChecked In cltTagSelection.CheckedItems txtSelectedTags.Text = txtSelectedTags.Text + tagChecked.ToString() + ", " Next End Sub

Thanks, Mike 谢谢,迈克

Ouch 1.1? 哎呀1.1? Is your employer trying to kill you? 你的老板想杀了你吗? I'd try to push up to 2.0 if I could. 如果可以的话,我会尽量提高到2.0。

To double check when you say the "Checked" event do you mean CheckedChanged? 要重复检查,当您说“已检查”事件时,您是说CheckedChanged吗? In 2.00 this works fine on desktop. 在2.00中,这在桌面上可以正常工作。 Is it a bug in 1.1? 是1.1版的错误吗?

If it is a bug (check your own code first before deciding this! Then check it again!) then I can suggest trying to capture the Leave event which occurs when a control loses focus. 如果它是一个错误(在确定此错误之前先检查您自己的代码!然后再次检查它!),那么我建议尝试捕获当控件失去焦点时发生的Leave事件。 Failing this you could databind a business object to the .Checked property and then fire your own event when your value changes. 失败的话,您可以将业务对象数据绑定到.Checked属性,然后在您的值更改时触发您自己的事件。 EG 例如

public class MyValues
{
    private bool _check;

    public bool Check
    {
        get
        {
            return _check;
        }
        set
        {
            if(_check != value)
            {
                _check = value;
                // todo: raise event!
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM