如何在列表框或列表视图中添加组合框项目(how to add combobox items in listbox or listview)

编程入门 行业动态 更新时间:2024-10-25 18:36:01
如何在列表框或列表视图中添加组合框项目(how to add combobox items in listbox or listview)

我想知道在我的项目中使用什么控件是Listview还是listbox ???。 我在我的项目上有一个comboBox控件,我想要做的是当我在我的组合框中选择1个项目时它会自动添加到listbox或listview上,当我选择多个项目时,我想将它添加到listbox或listview on newline上。 ..

这很简单,请帮我在列表框或列表视图中做到这一点。谢谢!

I want to know what control to be use on my project is it Listview or listbox???. I have a comboBox control on my project what I want to do is when I selected 1 item on my combobox it will automatically add on listbox or listview and when I selected more than 1 item I want to add it on listbox or listview on newline...

Is it simple, please help me to do that in listbox or listview..thanks!

最满意答案

Listbox > Is for viewing too but user can select it Listview > Is for viewing only, user cannot select also it viewing by five view directly cause it's for viewing only

如果您的项目希望从Combobox选择的内容中查看列表,那么您只需选择列表视图,但如果您想要查看,用户也可以选择它,更好地使用列表框,这取决于您。 此外,您可以通过将鼠标光标对准工具来了解工具的工作方式,然后它会弹出一个工具提示,用于编写工具的内容。

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged ListView1.Items.Add(ComboBox1.SelectedIndex) End Sub

这是在listview中查看您在组合框中选择的内容的代码

要清除列表视图或列表框中的所有项目,只需写入form_load即可

Listview.items.clear

为什么我在表单加载中说,导致列表只是为了查看,当然每次表单开始运行时,都需要空白列表,所以最好放在表单加载

UPDATE

删除列表框中的选定索引

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged ListBox1.Items.Remove(ListBox1.SelectedItem) End Sub Listbox > Is for viewing too but user can select it Listview > Is for viewing only, user cannot select also it viewing by five view directly cause it's for viewing only

If your project wanted the list to be viewing from what have been select by Combobox, then you just pick List View, but if you want for viewing also user can select it, better use listbox, so it's up to you. Also you can know how the Tools work by focus your mouse cursor to the tool, then it will pop up an tooltip that write what the tool for.

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged ListView1.Items.Add(ComboBox1.SelectedIndex) End Sub

That is the code to viewing in listview for what you select in combobox

For clearing all the item in the Listview or listbox, just write to your form_load

Listview.items.clear

Why i said in form load, cause the list just for viewing, of course every time the form begin to run, it will need blank list, so the best is put in form load

UPDATE

To remove the selected index in listbox

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged ListBox1.Items.Remove(ListBox1.SelectedItem) End Sub

更多推荐

本文发布于:2023-07-24 01:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240158.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   列表   视图   项目   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!