Question [Résolu] Taille colonne datagrid

Plus d'informations
il y a 5 ans 11 mois #25272 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
Pièces jointes :

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

Plus d'informations
il y a 5 ans 11 mois #25273 par Laurent Dardenne
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.

Tutoriels PowerShell

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

Plus d'informations
il y a 5 ans 11 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

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

Plus d'informations
il y a 5 ans 11 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 \&quot;dc=test,dc=com\&quot; | 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 = \&quot;Liste des SID\&quot;
$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 = \&quot;Recherche ID\&quot;
$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 = \&quot;Microsoft Sans Serif,10\&quot;
$SIDWindowsForm.Controls.Add($Label_ID_SID)

$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \&quot;\&quot;
$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 = \&quot;Microsoft Sans Serif,10\&quot;
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)

$DataGrid_SID = New-Object System.Windows.Forms.DataGrid
$DataGrid_SID.Name = \&quot;SID\&quot;
$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.

Plus d'informations
il y a 5 ans 11 mois #25280 par Laurent Dardenne
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(\&quot;System.Windows.Forms\&quot;«»)
[void][Reflection.Assembly]::LoadWithPartialName(\&quot;System.Drawing\&quot;«»)
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)&gt; $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 = \&quot;Liste des SID\&quot;
$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 = \&quot;Recherche ID\&quot;
$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 = \&quot;Microsoft Sans Serif,10\&quot;
$SIDWindowsForm.Controls.Add($Label_ID_SID)

$TextBox_ID_SID = New-Object System.Windows.Forms.TextBox
$TextBox_ID_SID.Text = \&quot;\&quot;
$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 = \&quot;Microsoft Sans Serif,10\&quot;
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)

$DataGrid_SID = New-Object System.Windows.Forms.DataGridView
$DataGrid_SID.Name = \&quot;SID\&quot;
$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.

Plus d'informations
il y a 5 ans 11 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.080 secondes
Propulsé par Kunena