CheckedListBox 填充文本控件
我有一个文本框,将填充由 CheckedListBox 控件驱动的逗号分隔列表。
这个想法是,当用户在列表中勾选项目时,它们将出现在上面的文本字段中。我已经做到了这一点:如果我检查一个项目,然后单击控件内的其他位置,则文本最终会出现在文本框中。我正在捕获我的控件上的点击事件。
如果我使用 item_checked 事件,则文本框中的列表不会更新,直到我检查第二个项目(此时文本框中仅显示已检查的第一个项目。)是否有解决办法?在 MSDN 上阅读似乎没有显示任何其他适用的事件。
我正在使用.net 1.1。
这是在事件陷阱上运行的方法。
<代码> Private Sub FillCheckedTagsTextBox()
txtSelectedTags.Text = ""
Dim tagChecked As Object
For Each tagChecked In cltTagSelection.CheckedItems
txtSelectedTags.Text = txtSelectedTags.Text + tagChecked.ToString() + ", "
Next
End Sub
谢谢, 麦克风
I have a text box that is going to be populated with a comma spereated list that is driven by a CheckedListBox control.
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.
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? Reading on MSDN doesn't seem to show any other events that would be applicable.
I'm using .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
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哎呀1.1?你的雇主想杀你吗?如果可以的话我会尝试提升到2.0。
当您说“Checked”事件时要仔细检查您的意思是CheckedChanged吗?在 2.00 中,这在桌面上运行良好。是1.1的bug吗?
如果这是一个错误(在决定之前先检查您自己的代码!然后再次检查!)那么我可以建议尝试捕获控件失去焦点时发生的离开事件。如果失败,您可以将业务对象数据绑定到 .Checked 属性,然后在值更改时触发您自己的事件。例如
Ouch 1.1? Is your employer trying to kill you? I'd try to push up to 2.0 if I could.
To double check when you say the "Checked" event do you mean CheckedChanged? In 2.00 this works fine on desktop. Is it a bug in 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. Failing this you could databind a business object to the .Checked property and then fire your own event when your value changes. E.G.