组合框中的多重选择!!! [英] Multi Selection inside a combo box!!!

查看:95
本文介绍了组合框中的多重选择!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我在Windows窗体应用程序中有一个组合框,我希望能够选择很多组合框,任何人有想法吗?请以一种非常简单的方式指导我!

Dear All,
I have a combo box within my windows form application, I want to be able to select many items of combobox, anyone there have an idea? Please guide me in a very easy way!!!

推荐答案

使用TextBox实例和在其中. System.Windows.Forms.ListBox可以与多个选择一起使用.在此自定义控件内,模拟行为类似于组合框,仅需进行多次选择即可为控件的用户提供相似的界面.顺便说一下,这是一种非常普通的方法.

请参阅:

http://msdn.microsoft.com/en-us/library/system. windows.forms.listbox.aspx [ ^ ].

这是System.Windows.Forms.ListBox的选择模式:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectionmode.aspx [ ^ ].

另请参见:
http://msdn.microsoft.com/en-us/library/system. windows.forms.textbox.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.forms.combobox.aspx [ ^ ].

-SA
Make a custom control or a user control with an instance of a TextBox and an instance of a ListBox in it. The System.Windows.Forms.ListBox can work with multiple selection. Inside this custom control, simulate behavior similar to the combo box, only with multiple selection, provide similar interface to the user of the control. This is a pretty usual approach, by the way.

Please see:

http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspx[^].

This are the selection modes of System.Windows.Forms.ListBox:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectionmode.aspx[^].

See also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx[^].

—SA


Private Sub InitializeMyListBox()
   ' Add items to the ListBox.
   listBox1.Items.Add("A")
   listBox1.Items.Add("C")
   listBox1.Items.Add("E")
   listBox1.Items.Add("F")
   listBox1.Items.Add("G")
   listBox1.Items.Add("D")
   listBox1.Items.Add("B")

   ' Sort all items added previously.
   listBox1.Sorted = True

   ' Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended

   ' Select three initial items from the list.
   listBox1.SetSelected(0, True)
   listBox1.SetSelected(2, True)
   listBox1.SetSelected(4, True)

   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub

Private Sub InvertMySelection()

   Dim x As Integer
   ' Loop through all items the ListBox.
   For x = 0 To listBox1.Items.Count - 1

      ' Determine if the item is selected.
      If listBox1.GetSelected(x) = True Then
         ' Deselect all items that are selected.
         listBox1.SetSelected(x, False)
      Else
         ' Select all items that are not selected.
         listBox1.SetSelected(x, True)
      End If
   Next x
   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub


这篇关于组合框中的多重选择!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆