Question
Peupler colonne Listview via CSV
- Laurent
- Auteur du sujet
- Hors Ligne
- Membre senior
-
Réduire
Plus d'informations
- Messages : 71
- Remerciements reçus 0
il y a 9 ans 5 mois #22729
par Laurent
Peupler colonne Listview via CSV a été créé par Laurent
Bonjour à tous,
J'explique mon problème
J'ai un fichier csv avec 3 colonne (colone1 = NOM, colonne 2 = MACHINE colonne 3 = REFERENCE délimiter par des [code:1];[/code:1]
J'ai dans mon interface graphique 3 colonne contenu dans un listView
Je souhaite peupler chacune de mes colonne via le CSV avec la commande suivante
[code:1]Import-Csv \"C:\Users\TEST\Desktop\CSV\Classeur122.csv\" -Delimiter \";\" | Sort-Object NOM | ForEach-Object { [void] $listView.Items.Add($_.NOM) }[/code:1]
Qui y a t'il a modifier pour peupler mes 3 colonnes grâce à ce CSV ?
MERCI A TOUS POUR VOTRE AIDE<br><br>Message édité par: laurenzo34000, à: 29/05/17 13:19
J'explique mon problème
J'ai un fichier csv avec 3 colonne (colone1 = NOM, colonne 2 = MACHINE colonne 3 = REFERENCE délimiter par des [code:1];[/code:1]
J'ai dans mon interface graphique 3 colonne contenu dans un listView
Je souhaite peupler chacune de mes colonne via le CSV avec la commande suivante
[code:1]Import-Csv \"C:\Users\TEST\Desktop\CSV\Classeur122.csv\" -Delimiter \";\" | Sort-Object NOM | ForEach-Object { [void] $listView.Items.Add($_.NOM) }[/code:1]
Qui y a t'il a modifier pour peupler mes 3 colonnes grâce à ce CSV ?
MERCI A TOUS POUR VOTRE AIDE<br><br>Message édité par: laurenzo34000, à: 29/05/17 13:19
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 9 ans 5 mois #22826
par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
#https://social.technet.microsoft.com/Forums/scriptcenter/en-US/43ba26cf-e27b-4c4c-8b46-c0d21cb5104a/powershell-edit-a-listviewitem?forum=ITCG
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 9 ans 5 mois #22827
par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
[code:1]
#creation fichier non trié
$moncsv=$mondossier+\"salaires.csv\"
$moncsv
@'
NOM;PRENOM;SALAIRE
L2V1;L2V2;L2V3
L1V1;L1V2;L1V3
L3V1;L3V2;L3V3
L4V1;L4V2;L4V3
'@ > $moncsv
$cont=Get-Content $moncsv
\"cont\"
$cont
$tab=Import-Csv $moncsv -Delimiter \";\" | Sort-Object NOM
$tab |ft -AutoSize
$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\";\"«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\";\"«»)+1)
\"deb\"
$deb
$pos=$deb.IndexOf(\";\"«»)
\"pos\"
$pos
#Read-Host \"touche\"
}
$nbrcol=$nbrcol+1
\"nbrcol\"
$nbrcol
\"creation ligne qui est colonne\"
$l=@()
0..$tab.Count|%{
$l+=$tab[$_].NOM
}
$l
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]]($l), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
[/code:1]
#creation fichier non trié
$moncsv=$mondossier+\"salaires.csv\"
$moncsv
@'
NOM;PRENOM;SALAIRE
L2V1;L2V2;L2V3
L1V1;L1V2;L1V3
L3V1;L3V2;L3V3
L4V1;L4V2;L4V3
'@ > $moncsv
$cont=Get-Content $moncsv
\"cont\"
$cont
$tab=Import-Csv $moncsv -Delimiter \";\" | Sort-Object NOM
$tab |ft -AutoSize
$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\";\"«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\";\"«»)+1)
\"deb\"
$deb
$pos=$deb.IndexOf(\";\"«»)
\"pos\"
$pos
#Read-Host \"touche\"
}
$nbrcol=$nbrcol+1
\"nbrcol\"
$nbrcol
\"creation ligne qui est colonne\"
$l=@()
0..$tab.Count|%{
$l+=$tab[$_].NOM
}
$l
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]]($l), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 9 ans 5 mois #22828
par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
Pièces jointes :
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 9 ans 5 mois #22829
par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
[code:1]
##########################
[void][System.Reflection.Assembly]::LoadWithPartialName(
\"System.Windows.Forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(
\"System.Drawing\"«»)
### Dialog form layout
# Create a Form
# with a TextBox and OK and Cancel buttons
$Dialog = New-Object System.Windows.Forms.Form
$Dialog.ClientSize = New-Object System.Drawing.Size(150, 60)
$Dialog.FormBorderStyle =
[System.Windows.Forms.FormBorderStyle]::FixedDialog
$Dialog.TopMost = $true
# TextBox
$Inp = New-Object System.Windows.Forms.TextBox
$Inp.Dock = [System.Windows.Forms.DockStyle]::Fill
$Inp.Left = 0;
$Inp.Top = 0;
# OK button
$OK = New-Object System.Windows.Forms.Button
$OK.Text = \"OK\"
$OK.Left = 0
$OK.Top = 30
# Cancel button
$Cancel = New-Object System.Windows.Forms.Button
$Cancel.Text = \"Cancel\"
$Cancel.Left = 75
$Cancel.Top = 30
# Set the form DialogResult
# depending on the button clicked
$OK_Click =
{
$Dialog.DialogResult =
[System.Windows.Forms.DialogResult]::OK
}
$OK.Add_Click($OK_Click)
$Cancel_Click =
{
$Dialog.DialogResult =
[System.Windows.Forms.DialogResult]::Cancel
}
$Cancel.Add_Click($Cancel_Click)
$Dialog.Controls.Add($Inp)
$Dialog.Controls.Add($OK)
$Dialog.Controls.Add($Cancel)
### End dialog form layout
$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = New-Object System.Drawing.Size(407, 390)
$form1.topmost = $true
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(25, 20)
$Button.Size = New-Object System.Drawing.Size(98, 23)
$Button.Text = \"Output\"
$Button.add_Click({FNwritedata})
$ListView = New-Object System.Windows.Forms.ListView
$ListView.Location = New-Object System.Drawing.Point(25, 55)
$ListView.Size = New-Object System.Drawing.Size(350, 310)
$ListView.View = [System.Windows.Forms.View]::«»Details
$ListView.checkboxes = $true
$ListView.LabelEdit = $true
# Full row select needed to be enabled
# for accepting mouse click events.
$ListView.FullRowSelect = $true
$LVcol1 = New-Object System.Windows.Forms.ColumnHeader
$LVcol1.Text = \"Column1\"
$LVcol1.Width = 165
$LVcol2 = New-Object System.Windows.Forms.ColumnHeader
$LVcol2.Text = \"Column2\"
$LVcol3 = New-Object System.Windows.Forms.ColumnHeader
$LVcol3.Text = \"Column3\"
$LVcol4 = New-Object System.Windows.Forms.ColumnHeader
$LVcol4.Text = \"Column4\"
$ListView.Columns.AddRange(
[System.Windows.Forms.ColumnHeader[]](
@($LVcol1, $LVcol2, $LVcol3, $LVcol4)))
### ListView event code
$LIstView_MouseClick =
{
# On right mouse click show the dialog form
# If the dialog result is OK change the subitem text
# The MouseClick event returns the clicked coordinates (X, Y)
# and ListViewHitTestInfo is used to get the right-clicked subitem
# $Inp.Text contains the text the user entered
if($Dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and
$_.Button -eq [Windows.Forms.MouseButtons]::Right)
{
$ListView.HitTest($_.X, $_.Y).Subitem.Text = $Inp.Text
}
}
$ListView.Add_MouseClick($ListView_MouseClick)
$Form1.Controls.Add($ListView)
$Form1.Controls.Add($Button)
function FNloaddata {
for ($line =1 ; $line -lt 5 ; $line ++ ) {
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]](@(\"a\",\"b\",\"c\",\"d\" )), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
}
}
function FNwritedata{
foreach ( $item in $ListView.Items) {
Write-Host $item.subitems[0].text $item.subitems[1].text $item.subitems[2].text $item.subitems[3].text
}
}
function FNloaddata2 {
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]]($l), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
}
#creation fichier non trié
$moncsv=$mondossier+\"salaires.csv\"
$moncsv
@'
NOM;PRENOM;SALAIRE;TEMP
L2V1;L2V2;L2V3;L2V4
L1V1;L1V2;L1V3;L1V4
L3V1;L3V2;L3V3;L3V4
L4V1;L4V2;L4V3;L4V4
'@ > $moncsv
$cont=Get-Content $moncsv
\"cont\"
$cont
$tab=Import-Csv $moncsv -Delimiter \";\" | Sort-Object NOM
$tab |ft -AutoSize
$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\";\"«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\";\"«»)+1)
\"deb\"
$deb
$pos=$deb.IndexOf(\";\"«»)
\"pos\"
$pos
#Read-Host \"touche\"
}
$nbrcol=$nbrcol+1
\"nbrcol\"
$nbrcol
\"creation ligne a charger\"
0..($tab.Count-1)|%{
$l=@()
$l+=$tab[$_].NOM
$l+=$tab[$_].PRENOM
$l+=$tab[$_].SALAIRE
$l+=$tab[$_].TEMP
$l
FNloaddata2
}
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
break
#https://social.technet.microsoft.com/Forums/scriptcenter/en-US/43ba26cf-e27b-4c4c-8b46-c0d21cb5104a/powershell-edit-a-listviewitem?forum=ITCG
#
Load and Run
FNloaddata2
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
#################################
[/code:1]
##########################
[void][System.Reflection.Assembly]::LoadWithPartialName(
\"System.Windows.Forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(
\"System.Drawing\"«»)
### Dialog form layout
# Create a Form
# with a TextBox and OK and Cancel buttons
$Dialog = New-Object System.Windows.Forms.Form
$Dialog.ClientSize = New-Object System.Drawing.Size(150, 60)
$Dialog.FormBorderStyle =
[System.Windows.Forms.FormBorderStyle]::FixedDialog
$Dialog.TopMost = $true
# TextBox
$Inp = New-Object System.Windows.Forms.TextBox
$Inp.Dock = [System.Windows.Forms.DockStyle]::Fill
$Inp.Left = 0;
$Inp.Top = 0;
# OK button
$OK = New-Object System.Windows.Forms.Button
$OK.Text = \"OK\"
$OK.Left = 0
$OK.Top = 30
# Cancel button
$Cancel = New-Object System.Windows.Forms.Button
$Cancel.Text = \"Cancel\"
$Cancel.Left = 75
$Cancel.Top = 30
# Set the form DialogResult
# depending on the button clicked
$OK_Click =
{
$Dialog.DialogResult =
[System.Windows.Forms.DialogResult]::OK
}
$OK.Add_Click($OK_Click)
$Cancel_Click =
{
$Dialog.DialogResult =
[System.Windows.Forms.DialogResult]::Cancel
}
$Cancel.Add_Click($Cancel_Click)
$Dialog.Controls.Add($Inp)
$Dialog.Controls.Add($OK)
$Dialog.Controls.Add($Cancel)
### End dialog form layout
$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = New-Object System.Drawing.Size(407, 390)
$form1.topmost = $true
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(25, 20)
$Button.Size = New-Object System.Drawing.Size(98, 23)
$Button.Text = \"Output\"
$Button.add_Click({FNwritedata})
$ListView = New-Object System.Windows.Forms.ListView
$ListView.Location = New-Object System.Drawing.Point(25, 55)
$ListView.Size = New-Object System.Drawing.Size(350, 310)
$ListView.View = [System.Windows.Forms.View]::«»Details
$ListView.checkboxes = $true
$ListView.LabelEdit = $true
# Full row select needed to be enabled
# for accepting mouse click events.
$ListView.FullRowSelect = $true
$LVcol1 = New-Object System.Windows.Forms.ColumnHeader
$LVcol1.Text = \"Column1\"
$LVcol1.Width = 165
$LVcol2 = New-Object System.Windows.Forms.ColumnHeader
$LVcol2.Text = \"Column2\"
$LVcol3 = New-Object System.Windows.Forms.ColumnHeader
$LVcol3.Text = \"Column3\"
$LVcol4 = New-Object System.Windows.Forms.ColumnHeader
$LVcol4.Text = \"Column4\"
$ListView.Columns.AddRange(
[System.Windows.Forms.ColumnHeader[]](
@($LVcol1, $LVcol2, $LVcol3, $LVcol4)))
### ListView event code
$LIstView_MouseClick =
{
# On right mouse click show the dialog form
# If the dialog result is OK change the subitem text
# The MouseClick event returns the clicked coordinates (X, Y)
# and ListViewHitTestInfo is used to get the right-clicked subitem
# $Inp.Text contains the text the user entered
if($Dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and
$_.Button -eq [Windows.Forms.MouseButtons]::Right)
{
$ListView.HitTest($_.X, $_.Y).Subitem.Text = $Inp.Text
}
}
$ListView.Add_MouseClick($ListView_MouseClick)
$Form1.Controls.Add($ListView)
$Form1.Controls.Add($Button)
function FNloaddata {
for ($line =1 ; $line -lt 5 ; $line ++ ) {
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]](@(\"a\",\"b\",\"c\",\"d\" )), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
}
}
function FNwritedata{
foreach ( $item in $ListView.Items) {
Write-Host $item.subitems[0].text $item.subitems[1].text $item.subitems[2].text $item.subitems[3].text
}
}
function FNloaddata2 {
$ListViewItem = New-Object System.Windows.Forms.ListViewItem([System.String[]]($l), -1)
$ListViewItem.StateImageIndex = 0
$ListView.Items.AddRange([System.Windows.Forms.ListViewItem[]](@($ListViewItem)))
}
#creation fichier non trié
$moncsv=$mondossier+\"salaires.csv\"
$moncsv
@'
NOM;PRENOM;SALAIRE;TEMP
L2V1;L2V2;L2V3;L2V4
L1V1;L1V2;L1V3;L1V4
L3V1;L3V2;L3V3;L3V4
L4V1;L4V2;L4V3;L4V4
'@ > $moncsv
$cont=Get-Content $moncsv
\"cont\"
$cont
$tab=Import-Csv $moncsv -Delimiter \";\" | Sort-Object NOM
$tab |ft -AutoSize
$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\";\"«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\";\"«»)+1)
\"deb\"
$deb
$pos=$deb.IndexOf(\";\"«»)
\"pos\"
$pos
#Read-Host \"touche\"
}
$nbrcol=$nbrcol+1
\"nbrcol\"
$nbrcol
\"creation ligne a charger\"
0..($tab.Count-1)|%{
$l=@()
$l+=$tab[$_].NOM
$l+=$tab[$_].PRENOM
$l+=$tab[$_].SALAIRE
$l+=$tab[$_].TEMP
$l
FNloaddata2
}
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
break
#https://social.technet.microsoft.com/Forums/scriptcenter/en-US/43ba26cf-e27b-4c4c-8b46-c0d21cb5104a/powershell-edit-a-listviewitem?forum=ITCG
#
Load and Run
FNloaddata2
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.Application]::Run($Form1)
#################################
[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 9 ans 5 mois #22830
par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
Pièces jointes :
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.043 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Peupler colonne Listview via CSV