Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27353

Listview and String problems...

$
0
0
Name:  4kqr.png
Views: 37
Size:  90.7 KB

Ok..

The code I have works, however... I have to use a messagebox to display all of the users from a single group. I'm trying to figure out how to add then to a string array and display them on a single line seperated by a ", " instead of clicking on a messagebox 900 times. The problem lies within the function at the end. Could anybody give me a hint? Or something to read? Been trying to figure this out all day.

Code:

Imports System.DirectoryServices
Imports System.Text

Public Class Form1

    Dim itm As New ListViewItem
    Dim str(30) As String
    Dim objItem As ListViewItem

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TextBox1.Text = "JOI"
        TextBox2.Text = "ALDC02"

        ListView1.View = System.Windows.Forms.View.Details
        ListView1.Columns.Add("Group", 100, HorizontalAlignment.Left)
        ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)

        ListView2.View = System.Windows.Forms.View.Details
        ListView2.Columns.Add("Group", 100, HorizontalAlignment.Left)
        ListView2.Columns.Add("Members", 100, HorizontalAlignment.Left)
        'ListView2.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ListView1.Items.Clear()
        ListView1.Items.Add(TextBox3.Text)

        For Each itam As ListViewItem In ListView1.Items
            objItem = ListView2.Items.Add(itam.Clone())
            With objItem
                .SubItems.Add(Load_Group(TextBox3.Text))
            End With
        Next

        For z As Integer = 0 To ListView2.Columns.Count - 1
            ListView2.Columns(z).Width = -2
        Next z

    End Sub

    Private Function Load_Group(ByVal mygroup As String) As String

        'This will list all users in the Domain

        Dim list As List(Of String) = New List(Of String)

        Dim strDirEntryPath As String
        strDirEntryPath = "WinNT://" & TextBox1.Text & "/" & TextBox2.Text & "/" & TextBox3.Text & ",group"


        Dim group As New DirectoryEntry(strDirEntryPath)
        Dim users As Object
        users = group.Invoke("members")
        Dim user1 As Object

        'I used a data table simply to sort
        'Probably a better way, but since I use data sets all the time that's what I know
        Dim DT As New DataTable

        Dim DC As New DataColumn("users")
        DT.Columns.Add(DC)

        Dim r1 As DataRow

        'Add each user to the data table
        For Each user1 In CType(users, IEnumerable)
            r1 = DT.NewRow
            Dim userEntry As New System.DirectoryServices.DirectoryEntry(user1)
            r1.Item(0) = userEntry.Name
            DT.Rows.Add(r1)
        Next

        'Use Data View to Sort Articles
        Dim DV As New DataView(DT)
        DV.Sort = "users asc"

        Dim intCount As Integer
        intCount = 0

        For intCount = 0 To DV.Count - 1
            list.Add(DV.Item(intCount).Row.Item(0))
        Next

        For Each user In list
            MessageBox.Show(user)
        Next

        Return list.ToString

    End Function

 

End Class

Attached Images
 

Viewing all articles
Browse latest Browse all 27353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>