Question Interface en WPF et usage de DataGrid.

Plus d'informations
il y a 12 ans 9 mois #15051 par DILLENSEGER Julien
Bonjour,

je suis confronté à un problème concernant le databinding avec WPF.

J'essaie de créer une interface graphique de gestion de l'AD sous Powershell.

Voici le code:
[code:1]

Add-Type -AssemblyName presentationframework
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase

[xml]$XAML = @'
<Window
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\";
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\";
Title=\"Gestionnaire des attributs des utilisateurs\" Height=\"518\" Width=\"790\">
<Grid>
<DataGrid AutoGenerateColumns=\"False\" Height=\"406\" HorizontalAlignment=\"Left\" Margin=\"12,32,0,0\" Name=\"DataGrid1\" VerticalAlignment=\"Top\" Width=\"730\" ItemsSource=\"{Binding Customers}\" SelectionMode=\"Extended\" SelectionUnit=\"Cell\">
<DataGrid.Columns>
<DataGridTextColumn Binding=\"{Binding Path=SamAccountName}\" Header=\"SamAccountName\" />
<DataGridTextColumn Binding=\"{Binding Path=Name}\" Header=\"Nom\" />
<DataGridTextColumn Binding=\"{Binding Path=Description}\" Header=\"Description\"/>
<DataGridTextColumn Binding=\"{Binding Path=Department}\" Header=\"Service\"/>
<DataGridTextColumn Binding=\"{Binding Path=Company}\" Header=\"Société\"/>
</DataGrid.Columns>

</DataGrid>
<Button Content=\"Valider\" Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"20,444,0,0\" Name=\"Btn_Valider\" VerticalAlignment=\"Top\" Width=\"75\" />
<Button Content=\"Modifier\" Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"200,444,0,0\" Name=\"Btn_Modifier\" VerticalAlignment=\"Top\" Width=\"75\" />
<Button Content=\"Quitter\" Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"667,444,0,0\" Name=\"Btn_Quitter\" VerticalAlignment=\"Top\" Width=\"75\" />

</Grid>
</Window>
'@
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Form=[Windows.Markup.XamlReader]::Load($reader)


$DataGrid1 = $form.FindName('DataGrid1')
$btnValider = $Form.FindName('Btn_Valider')
$btnQuitter = $Form.FindName('Btn_Quitter')
$btnModifier = $Form.FindName('Btn_Modifier')




# Récupération du domaine courant sous la forme domaine.local
$domaineLDAP=$env:USERDNSDOMAIN



# Transformation de la chaine DNS en chaine de connexion LDAP
# mondomaine.domaine.local -> mondomaine,DC=domaine,DC=local
# ou domaine.local -> domaine,DC=local
$domaineLDAP = $domaineLDAP.replace('.', ',DC=')



# ajout de DC= en tête de chaine
# domaine,DC=local -> DC=domaine,DC=local
$domaineLDAP=\"DC=$domaineLDAP\"

#Chemin de l'OU cible
$OU =



$script:emptyarray = New-Object System.Collections.ArrayList

$List = (Get-ADuser -Filter * -SearchScope onelevel -SearchBase \"$OU,$domaineLDAP\"«»)

Foreach ($utilisateur in $List) {


$tmpObject = Select-Object -InputObject \"\" SamAccountName,Name,Description,Department,Company
$tmpObject.SamAccountName = (get-aduser -Identity $utilisateur -Properties SamAccountName).SamAccountName
$tmpObject.Name = $utilisateur.name
$tmpObject.Description = (get-aduser -Identity $utilisateur -Properties Description).Description
$tmpObject.Department = (get-aduser -Identity $utilisateur -Properties department).department
$tmpObject.Company = (get-aduser -Identity $utilisateur -Properties Company).Company
$script:emptyarray += $tmpObject
}



$DataGrid1.ItemsSource = $emptyarray


Foreach ($element in $emptyarray) {
$user = (get-aduser -Identity $element.SamAccountName -Properties Name).Name
$description = (get-aduser -Identity $element.SamAccountName -Properties Description).Description
$service = (get-aduser -Identity $element.SamAccountName -Properties Department).Department
$societe = (get-aduser -Identity $element.SamAccountName -Properties Company).Company
}


$btnModifier.add_click({

})


$btnValider.add_click({})



$btnQuitter.add_click({$Form.close()})



#Show Form
$Form.ShowDialog() | out-null

[/code:1]


Mon souci concerne la sélection puis la modification d'un attribut d'un utilisateur par exemple la description.

Après l'achat de deux ouvrages sur le WPF et de nombreuses recherches sur internet, je suis bloqué.

Je recherche la syntaxe de sélection d'une cellule du datagrid à l'image de \"$donnee.IsChecked\" pour traiter les checkbox.

Merci de l'aide que vous pourrez m'apporter.

Cordialement.
Birkozo.

Message édité par: BIRKOZO, à: 5/06/13 10:43

Message édité par: BIRKOZO, à: 5/06/13 10:44<br><br>Message édité par: BIRKOZO, à: 5/06/13 13:16
Pièces jointes :

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

Plus d'informations
il y a 12 ans 9 mois #15079 par SiSMik
Salut,

As-tu déjà essayé la propriétés CurrentCell ?

[code:1]
dataGridView1.CurrentCell.ColumnIndex.ToString()
dataGridView1.CurrentCell.RowIndex.ToString()
[/code:1]

@+<br><br>Message édité par: benduru, à: 6/06/13 13:41

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

Plus d'informations
il y a 12 ans 9 mois #15177 par DILLENSEGER Julien
Bonjour Benduru,
merci pour ta réponse.

Je pense que mon principal problème est que le WPF émanant de Framework.NET je dois comprendre le fonctionnement de .NET

Or comme je n'ai aucune connaissance de .NET, je vais commencer par là.

Cordialement.

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

Plus d'informations
il y a 12 ans 9 mois #15180 par Laurent Dardenne
Salut,
BIRKOZO écrit:

Or comme je n'ai aucune connaissance de .NET, je vais commencer par là.

Le chemin est plus long, mais bien plus agréable :)
Si tu as des questions sur le sujet n'hésites pas, sous réserve de temps disponible.

Le début de la pelote :
broux.developpez.com/articles/dotnet/bien-debuter-en-dotnet/

Bonne lecture.

Tutoriels PowerShell

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

Plus d'informations
il y a 12 ans 9 mois #15219 par DILLENSEGER Julien
Bonjour Laurent,
j'ai fait quelques emplettes:
je me suis offert deux livres sur le c# 5.
Avec ça ça devrait aller...
Merci.
Cordialement.

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

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