dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

VB.NET Faces Off Against Classic VB : Page 10

VB.NET, the .NET Framework, and Visual Studio.NET together form a potent combination that can simplify your code and reduce errors; however, to truly supplant existing versions of VB as a RAD tool, Visual Studio needs Break-Edit-Continue.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Retrieve multiple selected items from a ListBox
In both classic VB and VB.NET, you can create a ListBox that lets users make multiple selections. There are two types of multiple selection—simple and extended. These examples use extended selection, which lets a user make multiple non-sequential selections by holding the control key down while clicking an item. In classic VB, set the MultiSelect property of the ListBox control to 2 (Extended). In VB.NET set the SelectionMode property to MultiExtended. A button on the form creates an array containing the user's selections and passes the array to a subroutine that displays the items. The following code shows the Click event for the buttons.




Classic VB

   Private Sub cmdGetListSelections_Click()
      Dim i As Integer
      Dim sArr() As String
      Dim selCount As Integer
      For i = 0 To List1.ListCount - 1
         If List1.Selected(i) Then
            ReDim Preserve sArr(selCount) As String
            sArr(selCount) = List1.List(i)
            selCount = selCount + 1
         End If
      Next
      Call showStringArray(sArr)
   End Sub
   Private Sub showStringArray(arr() As String)
      Dim s As String
      Dim i As Integer
      Dim arrCount As Integer
      On Error Resume Next
      arrCount = UBound(arr) + 1
      On Error GoTo 0
      If arrCount > 0 Then
         For i = 0 To arrCount - 1
            s = s & arr(i) & vbCrLf
         Next
         MsgBox s
      End If
   End Sub



VB.NET

   Private Sub btnGetListSelections_Click(ByVal sender _
      As System.Object, ByVal e As System.EventArgs) _
      Handles btnGetListSelections.Click
      Dim sArr(ListBox1.SelectedItems.Count - 1) _
         As String
      Dim anItem As String
      Dim i As Integer
      For Each anItem In ListBox1.SelectedItems
         sArr(i) = anItem
         i +=1
      Next
   End Sub
   
   Private Sub showStringArray(ByVal arr() As String)
      MessageBox.Show(Join(arr, _
      System.Environment.NewLine))
   End Sub
   End Class


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date