Question GridView : IList

Plus d'informations
il y a 15 ans 11 mois #6432 par Arthur
GridView : IList a été créé par Arthur
Bonjour,
Voilà en ce moment je suis en train de codé un petit programme qui récupère la liste des groupes utilisateurs AD puis ensuite en sélectionnant un groupe on peut visualiser les membres de ce groupe.
Seulement voilà je n'arrive pas à visualiser les membre du groupe dans un Gridview.

[code:1]$groupe=$listBox.SelectedItem
$connexion2 = [ADSI]\"WinNT://$machine/$groupe,group\"

$toto = $connexion2.PSBase.Invoke('Members') | foreach { $_.GetType().InvokeMember( 'Name', 'GetProperty', $Null , $_, $null)

$dataGrid.DataSource = $toto [/code:1]

J'avoue être perdus sur la nature de la variable $toto à cause de tous ces pipe :sick: mais tous ce que je sait, c'est qu'il faut que je la convertisse en une variable \"Ilist\" pour pouvoir l'utiliser.

Quelqu'un aurait il une solution soit pour convertir la variable ou carrément utiliser un autre moyen pour visualiser les membres du groupe ?Vaut il mieux utiliser un DataViewGrid si je compte afficher plusieurs informations pour chaque utilisateurs? Si oui comment ? :lol:

Edit : Bon j'ai changer un peut mon code : [code:1]

$toto2 = New-Object Collections.ArrayList

$toto = $connexion2.PSBase.Invoke('Members') | foreach { $_.GetType().InvokeMember( 'Name', 'GetProperty', $Null , $_, $null) }
[Void]$toto2.Add($toto)

$dataGrid.DataSource = $toto2
write-host \"$toto2\"

$form1.refresh()


[/code:1]

La commande write-host affiche les utilisateurs mais dans la fenêtre datagrid il m'affiche un nombre dans une colonne \&quot;length\&quot; :pinch:<br><br>Message édité par: bilbao, à: 26/03/10 11:07

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 15 ans 11 mois #6433 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:GridView : IList
Salut,
pas facile de tester un ensemble de lignes issues d'un script :huh:

De ce que je comprend, recherche \&quot;databinding\&quot; sur le forum, tu trouveras une exemple de liaison d'un arraylist avec une grille.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 15 ans 11 mois #6435 par Arthur
Réponse de Arthur sur le sujet Re:GridView : IList
Le problème c'est que le code est assez long (en plus c'est pratiquement que du code pour l'interface graphique) alors je ne voulait pas le poster en entier

Sinon a la place d'un GridView je suis passer par un RichTextBox ca marche bien mais bon le GridView est plus classe :P


[code:1]
function Liste-groupes {
param ([String] $machine=\&quot;.\&quot;«»)
$connexion = [ADSI]\&quot;WinNT://$machine\&quot;

$null=[reflection.assembly]::LoadWithPartialName(\&quot;System.Windows.Forms\&quot;«»)
$null=[reflection.assembly]::LoadWithPartialName(\&quot;System.Drawing\&quot;«»)
$null=[reflection.assembly]::LoadWithPartialName(\&quot;System.Data\&quot;«»)

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 25/03/2010 15:39
# Generated By: Administrateur
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(\&quot;System.Windows.Forms\&quot;«») | Out-Null
[reflection.assembly]::loadwithpartialname(\&quot;System.Drawing\&quot;«») | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$label2 = New-Object System.Windows.Forms.Label
$Export = New-Object System.Windows.Forms.Button
$List_Go = New-Object System.Windows.Forms.Button
$Choisisser_Groupe = New-Object System.Windows.Forms.Label
$listBox = New-Object System.Windows.Forms.ListBox
$dataGrid = New-Object System.Windows.Forms.DataGrid
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#
#Generated Event Script Blocks
#
#Provide Custom Code for events specified in PrimalForms.
$List_Go_OnClick=
{
#TODO: Place custom script here
$groupe=$listBox.SelectedItem
$connexion2 = [ADSI]\&quot;WinNT://$machine/$groupe,group\&quot;
$toto2 = New-Object Collections.ArrayList

$toto = $connexion2.PSBase.Invoke('Members') | foreach { $_.GetType().InvokeMember( 'Name', 'GetProperty', $Null , $_, $null) }
[Void]$toto2.Add($toto)

$dataGrid.DataSource = $toto2
write-host \&quot;$toto2\&quot;

$form1.refresh()


}

$Export_OnClick=
{
#TODO: Place custom script here

}

$handler_label2_Click=
{
#TODO: Place custom script here

}

$handler_Choisisser_Groupe_Click=
{
#TODO: Place custom script here

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}

#
#region Generated Form Code
$form1.Text = \&quot;Primal Form\&quot;
$form1.Name = \&quot;form1\&quot;
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 560
$System_Drawing_Size.Height = 488
$form1.ClientSize = $System_Drawing_Size

$label2.TabIndex = 5
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 388
$System_Drawing_Size.Height = 23
$label2.Size = $System_Drawing_Size
$label2.Text = \&quot;Liste des Groupes Utilisateurs de l''ordinateur : \&quot;
$label2.Font = New-Object System.Drawing.Font(\&quot;Lucida Console\&quot;,8.25,0,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 21
$label2.Location = $System_Drawing_Point
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Name = \&quot;label2\&quot;
$label2.add_Click($handler_label2_Click)

$form1.Controls.Add($label2)

$Export.TabIndex = 4
$Export.Name = \&quot;Export\&quot;
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 23
$Export.Size = $System_Drawing_Size
$Export.UseVisualStyleBackColor = $True

$Export.Text = \&quot;Exporter en CSV !\&quot;

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 419
$System_Drawing_Point.Y = 453
$Export.Location = $System_Drawing_Point
$Export.DataBindings.DefaultDataSourceUpdateMode = 0
$Export.add_Click($Export_OnClick)

$form1.Controls.Add($Export)

$List_Go.TabIndex = 3
$List_Go.Name = \&quot;List_Go\&quot;
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$List_Go.Size = $System_Drawing_Size
$List_Go.UseVisualStyleBackColor = $True

$List_Go.Text = \&quot;Lister ! Go !\&quot;

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 325
$System_Drawing_Point.Y = 95
$List_Go.Location = $System_Drawing_Point
$List_Go.DataBindings.DefaultDataSourceUpdateMode = 0
$List_Go.add_Click($List_Go_OnClick)

$form1.Controls.Add($List_Go)

$Choisisser_Groupe.TabIndex = 2
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 145
$System_Drawing_Size.Height = 23
$Choisisser_Groupe.Size = $System_Drawing_Size
$Choisisser_Groupe.Text = \&quot;Choisissez un groupe\&quot;
$Choisisser_Groupe.Font = New-Object System.Drawing.Font(\&quot;Lucida Sans Unicode\&quot;,8.25,0,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 95
$Choisisser_Groupe.Location = $System_Drawing_Point
$Choisisser_Groupe.DataBindings.DefaultDataSourceUpdateMode = 0
$Choisisser_Groupe.Name = \&quot;Choisisser_Groupe\&quot;
$Choisisser_Groupe.add_Click($handler_Choisisser_Groupe_Click)

$form1.Controls.Add($Choisisser_Groupe)

$listBox.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 120
$System_Drawing_Size.Height = 30
$listBox.Size = $System_Drawing_Size
$listBox.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox.Name = \&quot;listBox1\&quot;
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 163
$System_Drawing_Point.Y = 88
$listBox.Location = $System_Drawing_Point
$listBox.TabIndex = 1
$list_group = $connexion.PSBase.Children | Where { $_.PSBase.schemaClassName -eq 'group' }
$list_group | foreach {
$listBox.Items.Add(\&quot;$($_.Name )\&quot;«»)
}
$form1.Controls.Add($listBox)

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 491
$System_Drawing_Size.Height = 317
$dataGrid.Size = $System_Drawing_Size
$dataGrid.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid.Name = \&quot;dataGrid1\&quot;
$dataGrid.DataMember = \&quot;\&quot;
$dataGrid.TabIndex = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 124
$dataGrid.Location = $System_Drawing_Point

$form1.Controls.Add($dataGrid)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

}


[/code:1]

Message édité par: bilbao, à: 26/03/10 13:42<br><br>Message édité par: bilbao, à: 26/03/10 13:43

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 15 ans 11 mois #6444 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:GridView : IList
bilbao écrit:

Le problème c'est que le code est assez long (en plus c'est pratiquement que du code pour l'interface graphique) alors je ne voulait pas le poster en entier

Tu peux aussi le joindre en pièce jointe.

Le pb est que tu manipules un tableau de chaîne de caractères et pas un tableau d'objet.
Il faut donc créer un objet à partir des infos récupérées :
[code:1]
$toto2 = New-Object Collections.ArrayList

$toto = $connexion2.PSBase.Invoke('Members') | foreach { $_.GetType().InvokeMember( 'Name', 'GetProperty', $Null , $_, $null) }

$toto|
Foreach {
$Objet=New-object PSObject
$Objet|Add-member noteproperty Nom $_ -pass|
Add-member noteproperty AutreInfo $Machine
[Void]$toto2.Add($Objet)
}
$dataGrid.DataSource = $toto2
write-host \&quot;$toto2\&quot;
$form1.refresh()
}
[/code:1]
La v2 :
[code:1]
$Liste = New-Object Collections.ArrayList

$connexion2.PSBase.Invoke('Members') |
Foreach {
$Nom=$_.GetType().InvokeMember( 'Name', 'GetProperty', $Null , $_, $null)
[Void]$Liste.Add((New-object PSObject|
Add-member noteproperty Nom $Nom -pass|
Add-member noteproperty AutreInfo $Machine -pass)
)
}
$dataGrid.DataSource = $Liste
}
[/code:1]
Celle-ci est,hélas, sans riri, ni fifi ni toto :P<br><br>Message édité par: Laurent Dardenne, à: 27/03/10 12:55

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 15 ans 11 mois #6449 par Arthur
Réponse de Arthur sur le sujet Re:GridView : IList
Merci mille fois ca marche parfaitement. :woohoo:
Concernant les \&quot;Toto\&quot; je manque souvent d'idées pour le nom de mes variables quand j'écris mes fonctions :P
Bien sûr dans la version final je change les noms à chaque fois.

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.050 secondes
Propulsé par Kunena