Question Foncition recherche et Filtre dans un datagrid

Plus d'informations
il y a 5 ans 11 mois #25355 par SCHAMB
Bonjour,

Je reviens vers vous avec mon petit programme qui affiche dans un datagrid les sid.
J'ai mis une textbox qui une fois remplis recherche les éléments dans la datagrid jusque la tout va bien.
Cependant, je rencontre des difficultés à mettre en place mon rowfilter.
Pouvez vous m'aider svp?

Code:

[code:1][void][Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
Function SID
{
param (
[Parameter(Mandatory = $True, position = 0)]
$SID,
[Parameter(Mandatory = $True, position = 1)]
$Name,
[Parameter(Mandatory = $True, position = 2)]
$Login
)

[pscustomobject]@{
PSTypeName = 'data';
SID = $SID;
Name = $Name;
Login = $Login;
}


} # New-data

function Get-SID
{
$ArrayList_SID = New-Object System.Collections.ArrayList
$t = Get-ADUser -Filter * -SearchBase \"dc=test,dc=com\" | Select Name, @{ label = \"login\"; expression = { $_.SamAccountName } }, SID
$ArrayList_SID.Addrange($T)
$DataGrid_SID.DataSource = $ArrayList_SID
$column = $DataGrid_SID.Columns[0]
$column.Width = 120
$column = $DataGrid_SID.Columns[1]
$column.Width = 90
$column = $DataGrid_SID.Columns[2]
$column.Width = 280
}

$SIDWindowsForm_CleanUp_FormClosed = {
try
{
$TextBox_ID_SID.remove_TextChanged($TextBox_ID_SID_TextChanged)
$DataGrid_SID.remove_CellPainting($DataGrid_SID_CellPainting)
}
catch
{
Out-Null
}
}

$TextBox_ID_SID_TextChanged = {
$DataGrid_SID.Refresh()
$DataGrid_SID.DataSource.DefaultView.RowFilter = \"name LIKE '*$($TextBox_ID_SID.Text)*'\"
}

$DataGrid_SID_CellPainting = [System.Windows.Forms.DataGridViewCellPaintingEventHandler]{


if ($_.RowIndex -ge 0 -and $_.ColumnIndex -ge 0 -and $TextBox_ID_SID.Text -ne \"\"«»)
{
$_.Handled = $true
$_.PaintBackground($_.CellBounds, $true)

if ($sw = $TextBox_ID_SID.Text)
{
[string]$val = $_.FormattedValue
[int]$sindx = $val.ToLower().IndexOf($sw.ToLower())
[int]$sCount = 1
while ($sindx -ge 0)
{
$hl_rect = New-Object System.Drawing.Rectangle
$hl_rect.Y = $_.CellBounds.Y + 2
$hl_rect.Height = $_.CellBounds.Height - 5

$sBefore = $val.Substring(0, $sindx)
$sWord = $val.Substring($sindx, $sw.Length)
$s1 = [System.Windows.Forms.TextRenderer]::MeasureText($_.Graphics, $sBefore, $_.CellStyle.Font, $_.CellBounds.Size)
$s2 = [System.Windows.Forms.TextRenderer]::MeasureText($_.Graphics, $sWord, $_.CellStyle.Font, $_.CellBounds.Size)

if ($s1.Width -gt 5)
{
$hl_rect.X = $_.CellBounds.X + $s1.Width - 5
$hl_rect.Width = $s2.Width - 6
}
else
{
$hl_rect.X = $_.CellBounds.X + 2
$hl_rect.Width = $s2.Width - 6
}

$hl_brush = new-object System.Drawing.SolidBrush Yellow


$_.Graphics.FillRectangle($hl_brush, $hl_rect)

$hl_brush.Dispose()
$sindx = $val.ToLower().IndexOf($sw.ToLower(), $sCount++)
}

$_.PaintContent($_.CellBounds)
}

}
}

$SIDWindowsForm = New-Object System.Windows.Forms.Form
$SIDWindowsForm.Text = \"Liste des SID\"
$SIDWindowsForm.TopMost = $true
$SIDWindowsForm.Width = 610
$SIDWindowsForm.Height = 390
$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\"
$TextBox_ID_SID.add_TextChanged($TextBox_ID_SID_TextChanged)
$SIDWindowsForm.Controls.Add($TextBox_ID_SID)

$DataGrid_SID = New-Object System.Windows.Forms.DataGridView
$DataGrid_SID.Name = \"SID\"
$DataGrid_SID.Width = 548
$DataGrid_SID.Height = 276
$DataGrid_SID.Location = New-Object System.Drawing.Point(24, 40)
$DataGrid_SID.add_CellPainting($DataGrid_SID_CellPainting)

$SIDWindowsForm.Controls.Add($DataGrid_SID)

#Clean window
$SIDWindowsForm.add_FormClosed($SIDWindowsForm_CleanUp_FormClosed)

[void]$SIDWindowsForm.ShowDialog()[/code:1]<br><br>Message édité par: Arnaud, à: 4/05/18 08:20

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

Plus d'informations
il y a 5 ans 10 mois #25369 par SCHAMB
Avez vous des idées?

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

Plus d'informations
il y a 5 ans 10 mois #25412 par SCHAMB
bonjour,
je suis toujours bloqué je ne vois pas ce qui cloche...
Avez vous pu vous pencher sur le problème?
merci

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

Plus d'informations
il y a 5 ans 9 mois #25423 par Arnaud Petitjean
Bonjour Stew,

Je suis désolé mais je ne fais pas souvent de GUI avec WPF; donc il m'est difficile de pouvoir t'aider sans y consacrer beaucoup de temps...

Je ne vais pas t'aider sur ce point, mais j'aurai tendance à te suggérer d'utiliser le produit PowerShell Universal Dashboard qui te permettra de faire beaucoup plus et beaucoup mieux ce que tu fais aujourd'hui avec WPF.

Universal Dasboard intègre nativement des DataGrid avec fonction de filtre. Je les utilise et ça marche super bien.

J'ai fait une vidéo de présentation et de prise en main d'universal Dashboard sur Youtube, tu la trouveras ici :
FrPSUG 2018/03/26 Universal Dashboard (Arnaud Petitjean)

Bonne journée,

Arnaud

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

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

Plus d'informations
il y a 5 ans 9 mois #25477 par SCHAMB
Merci je vais me pencher sur ta solution

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

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