I’m using Visual Studio to create a WPF GUI for a powershell script. How can I select a particular column to add data to?
I’ve looked around online and I can’t seem to find a good solution for this.
Powershell:
#=========================================================================== # Actually make the objects work #=========================================================================== Function Get-ADGroups($userID){ Get-ADPrincipalGroupMembership $userID | select name } Function Get-UserInfo($userID){ Get-ADUser $userID -Properties * | select Name,Title,EmailAddress,telephoneNumber,Department,lockedOut,PasswordLastSet } Function Get-Manager($userID){ $manager = Get-ADUser $userID -Properties * | select Manager #$manager | Out-Host $manager = $manager -replace ".*CN=" -replace ",.*" #$manager | Out-Host return $manager } Function Get-GroupDescriptions($userID){ $groups = Get-ADPrincipalGroupMembership $userID | select name $descriptions = @() foreach($group in $groups){ Try{ $descriptions += Get-ADGroup $group.Name -Properties * | select Description }Catch{ Write-Host 'Not a valid group' -ForegroundColor Cyan $descriptions += 'No Description' } } return $descriptions } # $WPFlistViewADGroup = $form.FindName("ADGroup") # $WPFlistViewDescription = $form.FindName("Description") $WPFbuttonQueryAD.Add_Click({ Get-UserInfo $WPFtextBoxUserID.Text | % {($WPFtextBlockName.Text=$_.Name),($WPFtextBlockDepartment.Text=$_.Department),($WPFtextBlockEmail.Text=$_.EmailAddress),` ($WPFtextBlockLocked.Text=$_.lockedOut),($WPFtextBlockPhone.Text=$_.telephoneNumber),($WPFtextBlockReset.Text=$_.PasswordLastSet),` ($WPFtextBlockTitle.Text=$_.Title)} Get-Manager $WPFtextBoxUserID.Text | % {$WPFtextBlockManager.Text=$_} $WPFlistView.Items.Clear() Get-ADGroups $WPFtextBoxUserID.Text | % {$WPFlistView.AddChild($_.Name)} Get-GroupDescriptions $WPFtextBoxUserID.Text | % {$WPFListView.AddChild($_)} })
XAML:
$inputXML = @" <Window x:Class="Service_Center_Toolkit.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Service_Center_Toolkit" mc:Ignorable="d" Title="Service Center Toolkit" Height="450" Width="700"> <Grid> <Label x:Name="label" Content="Username:" HorizontalAlignment="Left" VerticalAlignment="Top"/> <TextBox x:Name="textBoxUserId" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="66,3,0,0" ToolTip="Enter the network ID of a user."/> <Button x:Name="buttonQueryAD" Content="Search" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="191,4,0,0"/> <ListView x:Name="listView" HorizontalAlignment="Left" Height="152" VerticalAlignment="Top" Width="672" Margin="10,244,0,0"> <ListView.View> <GridView> <GridViewColumn Header="AD Group" Width="336"/> <GridViewColumn Header="Decription" Width="336" DisplayMemberBinding="{Binding Description}"/> </GridView> </ListView.View> </ListView> <Label x:Name="label1" Content="Locked Out:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,187,0,0"/> <Label x:Name="label2" Content="Last Password Reset:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,213,0,0"/> <Label x:Name="label3" Content="E-Mail:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,109,0,0"/> <Label x:Name="label4" Content="Phone:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,135,0,0"/> <Label x:Name="label5" Content="Name:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,31,0,0"/> <Label x:Name="label6" Content="Title:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,57,0,0"/> <Label x:Name="label7" Content="Manager:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,83,0,0"/> <Label x:Name="label8" Content="Department:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,161,0,0"/> <TextBlock x:Name="textBlockName" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Margin="134,36,0,0" Text="TextBlock"/> <TextBlock x:Name="textBlockTitle" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,62,0,0"/> <TextBlock x:Name="textBlockManager" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,88,0,0"/> <TextBlock x:Name="textBlockEmail" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,114,0,0"/> <TextBlock x:Name="textBlockPhone" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,140,0,0"/> <TextBlock x:Name="textBlockDepartment" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,166,0,0"/> <TextBlock x:Name="textBlockLocked" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,192,0,0"/> <TextBlock x:Name="textBlockReset" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="134,218,0,0"/> </Grid> </Window> "@
submitted by /u/Here_And_Now
[link] [comments]
The post WPF listView, how do I select a column? appeared first on How to Code .NET.