Question Peupler colonne Listview via CSV

Plus d'informations
il y a 9 ans 5 mois #22729 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

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

Plus d'informations
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.

Plus d'informations
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+\&quot;salaires.csv\&quot;
$moncsv
@'
NOM;PRENOM;SALAIRE
L2V1;L2V2;L2V3
L1V1;L1V2;L1V3
L3V1;L3V2;L3V3
L4V1;L4V2;L4V3
'@ &gt; $moncsv
$cont=Get-Content $moncsv
\&quot;cont\&quot;
$cont

$tab=Import-Csv $moncsv -Delimiter \&quot;;\&quot; | Sort-Object NOM
$tab |ft -AutoSize

$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\&quot;;\&quot;«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\&quot;;\&quot;«»)+1)
\&quot;deb\&quot;
$deb
$pos=$deb.IndexOf(\&quot;;\&quot;«»)
\&quot;pos\&quot;
$pos
#Read-Host \&quot;touche\&quot;
}
$nbrcol=$nbrcol+1
\&quot;nbrcol\&quot;
$nbrcol

\&quot;creation ligne qui est colonne\&quot;
$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.

Plus d'informations
il y a 9 ans 5 mois #22828 par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
x

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

Plus d'informations
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(
\&quot;System.Windows.Forms\&quot;«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(
\&quot;System.Drawing\&quot;«»)


### 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 = \&quot;OK\&quot;
$OK.Left = 0
$OK.Top = 30

# Cancel button

$Cancel = New-Object System.Windows.Forms.Button
$Cancel.Text = \&quot;Cancel\&quot;
$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 = \&quot;Output\&quot;
$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 = \&quot;Column1\&quot;
$LVcol1.Width = 165
$LVcol2 = New-Object System.Windows.Forms.ColumnHeader
$LVcol2.Text = \&quot;Column2\&quot;
$LVcol3 = New-Object System.Windows.Forms.ColumnHeader
$LVcol3.Text = \&quot;Column3\&quot;
$LVcol4 = New-Object System.Windows.Forms.ColumnHeader
$LVcol4.Text = \&quot;Column4\&quot;

$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[]](@(\&quot;a\&quot;,\&quot;b\&quot;,\&quot;c\&quot;,\&quot;d\&quot; )), -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+\&quot;salaires.csv\&quot;
$moncsv
@'
NOM;PRENOM;SALAIRE;TEMP
L2V1;L2V2;L2V3;L2V4
L1V1;L1V2;L1V3;L1V4
L3V1;L3V2;L3V3;L3V4
L4V1;L4V2;L4V3;L4V4
'@ &gt; $moncsv
$cont=Get-Content $moncsv
\&quot;cont\&quot;
$cont

$tab=Import-Csv $moncsv -Delimiter \&quot;;\&quot; | Sort-Object NOM
$tab |ft -AutoSize

$nbrcol=0
$deb=$cont[0]
$pos=$deb.IndexOf(\&quot;;\&quot;«»)
while($pos -ne -1){
$nbrcol=$nbrcol+1;
$deb=$deb.Substring($deb.IndexOf(\&quot;;\&quot;«»)+1)
\&quot;deb\&quot;
$deb
$pos=$deb.IndexOf(\&quot;;\&quot;«»)
\&quot;pos\&quot;
$pos
#Read-Host \&quot;touche\&quot;
}
$nbrcol=$nbrcol+1
\&quot;nbrcol\&quot;
$nbrcol

\&quot;creation ligne a charger\&quot;
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.

Plus d'informations
il y a 9 ans 5 mois #22830 par crogiez
Réponse de crogiez sur le sujet Re:Peupler colonne Listview via CSV
x

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

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