Question [Résolu] Taille colonne datagrid
- SCHAMB
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 12
- Remerciements reçus 0
il y a 5 ans 5 mois #25272
par SCHAMB
[Résolu] Taille colonne datagrid a été créé par SCHAMB
Bonjour à tous,
Je suis un peu pommé et j'espère que vous pourrez répondre à ma question.
En ce moment, je fais un petit utilitaire sous powershell avec une interface graphique.
J'arrive à alimenter ma datagrid comme il se doit, mais mon problème c'est la taille des colonnes.
Il y aurait il un moyen de définir une taille pour chaque colonne?
je vous joins des capture ainsi que le code
[code:1]function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$script:«»SID = Get-ADUser -Filter * -SearchBase \"dc=test,dc=com\" | Select SID, Name, SamAccountName | Sort -Property Name
$ArrayList_SID.AddRange($SID)
$DataGrid_SID.DataSource = $ArrayList_SID
}
#######################
#Fenêtre Liste des SID#
#######################
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({Get-SID})
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_DsQuery.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGrid
$DataGrid_SID.Name = \"DsQuery\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[/code:1]
Merci pour votre aide
Message édité par: Arnaud, à: 9/04/18 13:56<br><br>Message édité par: Arnaud, à: 10/04/18 15:09
Je suis un peu pommé et j'espère que vous pourrez répondre à ma question.
En ce moment, je fais un petit utilitaire sous powershell avec une interface graphique.
J'arrive à alimenter ma datagrid comme il se doit, mais mon problème c'est la taille des colonnes.
Il y aurait il un moyen de définir une taille pour chaque colonne?
je vous joins des capture ainsi que le code
[code:1]function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$script:«»SID = Get-ADUser -Filter * -SearchBase \"dc=test,dc=com\" | Select SID, Name, SamAccountName | Sort -Property Name
$ArrayList_SID.AddRange($SID)
$DataGrid_SID.DataSource = $ArrayList_SID
}
#######################
#Fenêtre Liste des SID#
#######################
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({Get-SID})
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_DsQuery.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGrid
$DataGrid_SID.Name = \"DsQuery\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[/code:1]
Merci pour votre aide
Message édité par: Arnaud, à: 9/04/18 13:56<br><br>Message édité par: Arnaud, à: 10/04/18 15:09
Pièces jointes :
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6290
- Remerciements reçus 67
il y a 5 ans 5 mois #25273
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Taille colonne datagrid
Salut,
recherche 'c# datagrid column width' tu devrais trouvé qq pistes.
Je n'ai pas testé car ton code est incomplet.
recherche 'c# datagrid column width' tu devrais trouvé qq pistes.
Je n'ai pas testé car ton code est incomplet.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- SCHAMB
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 12
- Remerciements reçus 0
il y a 5 ans 5 mois #25277
par SCHAMB
Réponse de SCHAMB sur le sujet Re:Taille colonne datagrid
oui le code est incomplet en effet, j'ai juste mis la déclaration des variables pour voir si j'avais loupé quelque choses.
Je regarde pour le datagrid column width... je
Je regarde pour le datagrid column width... je
Connexion ou Créer un compte pour participer à la conversation.
- SCHAMB
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 12
- Remerciements reçus 0
il y a 5 ans 5 mois #25279
par SCHAMB
Réponse de SCHAMB sur le sujet Re:Taille colonne datagrid
Voici le code (à noter que la partie recherche n'est pas encore implémentée si vous avez des idées je suis preneur
) :
function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$script:SID = Get-ADUser -Filter * -SearchBase \"dc=test,dc=com\" | Select SID, Name, SamAccountName | Sort -Property Name
$ArrayList_SID.AddRange($SID)
$DataGrid_SID.DataSource = $ArrayList_SID
}
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({ Get-SID })
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGrid
$DataGrid_SID.Name = \"SID\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[void]$SIDWindowsForm.ShowDialog()
j'ai essayé avec $DataGrid_SID.Columns[3].Width = 600 sans trop de succès<br><br>Message édité par: STEW, à: 9/04/18 18:29

function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$script:SID = Get-ADUser -Filter * -SearchBase \"dc=test,dc=com\" | Select SID, Name, SamAccountName | Sort -Property Name
$ArrayList_SID.AddRange($SID)
$DataGrid_SID.DataSource = $ArrayList_SID
}
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({ Get-SID })
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGrid
$DataGrid_SID.Name = \"SID\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[void]$SIDWindowsForm.ShowDialog()
j'ai essayé avec $DataGrid_SID.Columns[3].Width = 600 sans trop de succès<br><br>Message édité par: STEW, à: 9/04/18 18:29
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6290
- Remerciements reçus 67
il y a 5 ans 5 mois #25280
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Taille colonne datagrid
Il faut utiliser un autre composant :
Une ébauche rapido :
[code:1]
#https://docs.microsoft.com/fr-fr/dotnet/framework/winforms/controls/differences-between-the-windows-forms-datagridview-and-datagrid-controls
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
Function New-data{
param(
[Parameter(Mandatory=$True,position=0)]
$SID,
[Parameter(Mandatory=$True,position=1)]
$Name,
[Parameter(Mandatory=$True,position=2)]
$SamAccountName
)
[pscustomobject]@{
PSTypeName='data';
SID=$SID;
Name=$Name;
SamAccountName=$SamAccountName;
}
}# New-data
function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$t=@(
New-data 123 Nom1 'nom1.fr'
New-data 124 Nom2 'nom2.fr'
New-data 125 Nom3 'nom3.fr'
New-data 126 Nom4 'nom4.fr'
New-data 127 Nom5 'nom5.fr'
)
$ArrayList_SID.Addrange($T)> $null
$DataGrid_SID.DataSource = $ArrayList_SID
$column = $DataGrid_SID.Columns[0]
$column.Width = 120
$column = $DataGrid_SID.Columns[1];
$column.Width = 80;
$column = $DataGrid_SID.Columns[2];
$column.Width = 40;
}
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({ Get-SID })
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGridView
$DataGrid_SID.Name = \"SID\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[void]$SIDWindowsForm.ShowDialog()
[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 9/04/18 19:23
Une ébauche rapido :
[code:1]
#https://docs.microsoft.com/fr-fr/dotnet/framework/winforms/controls/differences-between-the-windows-forms-datagridview-and-datagrid-controls
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
Function New-data{
param(
[Parameter(Mandatory=$True,position=0)]
$SID,
[Parameter(Mandatory=$True,position=1)]
$Name,
[Parameter(Mandatory=$True,position=2)]
$SamAccountName
)
[pscustomobject]@{
PSTypeName='data';
SID=$SID;
Name=$Name;
SamAccountName=$SamAccountName;
}
}# New-data
function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$t=@(
New-data 123 Nom1 'nom1.fr'
New-data 124 Nom2 'nom2.fr'
New-data 125 Nom3 'nom3.fr'
New-data 126 Nom4 'nom4.fr'
New-data 127 Nom5 'nom5.fr'
)
$ArrayList_SID.Addrange($T)> $null
$DataGrid_SID.DataSource = $ArrayList_SID
$column = $DataGrid_SID.Columns[0]
$column.Width = 120
$column = $DataGrid_SID.Columns[1];
$column.Width = 80;
$column = $DataGrid_SID.Columns[2];
$column.Width = 40;
}
$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 540
$SIDWindowsForm.Height = 380
$SIDWindowsForm.StartPosition = 'CenterScreen'
$SIDWindowsForm.add_Load({ Get-SID })
$Label_ID_SID = New-Object System.Windows.Forms.Label
$Label_ID_SID.Text = \"Recherche ID\"
$Label_ID_SID.AutoSize = $true
$Label_ID_SID.Width = 60
$Label_ID_SID.Height = 10
$Label_ID_SID.Location = New-Object System.Drawing.Point(10, 10)
$Label_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($Label_ID_SID)
$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \"\"
$TextBox_ID_SID.Width = 60
$TextBox_ID_SID.Height = 20
$TextBox_ID_SID.Location = New-Object System.Drawing.Point(102, 8)
$TextBox_ID_SID.Font = \"Microsoft Sans Serif,10\"
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)
$DataGrid_SID = New-Object System.Windows.Forms.DataGridView
$DataGrid_SID.Name = \"SID\"
$DataGrid_SID.Width = 486
$DataGrid_SID.Height = 264
$DataGrid_SID.Location = New-Object System.Drawing.Point(20, 40)
$SIDWindowsForm.Controls.Add($DataGrid_SID)
[void]$SIDWindowsForm.ShowDialog()
[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 9/04/18 19:23
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- SCHAMB
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 12
- Remerciements reçus 0
il y a 5 ans 5 mois #25282
par SCHAMB
Réponse de SCHAMB sur le sujet Re:Taille colonne datagrid
merci laurent ça fonctionne tres bien. je m'occupe maintenant de la fonction recherche
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.057 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les initiés
- [Résolu] Taille colonne datagrid