Answer the question
In order to leave comments, you need to log in
How to break connection between ComboBox?
Hello!
There is this script:
#функция отрисовки диалога выбора файла
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV (*.csv)| *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
#вызываем функцию диалога выбора файла и запоминаем результат
$patch_csv = Get-FileName # нужно добавить проверку, не был ли путь пустым ( либо не нажали ли отмену)
#импортируем csv
$import_csv = Import-CSV $patch_csv
#
$a = @()
#
$import_csv | get-member | ForEach { $a = $a + $_.name }
#
$attribute_ad = "sn","GivenName","DisplayName","Description","mobile","otherTelephone","telephoneNumber","Title","Department","Company","mail"
#
Add-Type -assembly System.Windows.Forms
$main_form = New-Object System.Windows.Forms.Form
$main_form.Text ='Видемое название формы'
$main_form.Width = 300
$main_form.Height = 200
$main_form.AutoSize = $true
#
[System.Windows.Forms.TextBox[]]$TextBox = @()
#
[System.Windows.Forms.ComboBox[]]$ComboBox = @()
for ($i=0;$i -lt $attribute_ad.Length;$i++) {
# объявляем TextBox и запихиваем в переменную $TEMP
$TEMP = New-Object System.Windows.Forms.TextBox
# добавляем TextBox в массив TextBox`ов
$TextBox += $TEMP
# вычисляем высоту на которой должен располагаться TextBox и загоняем в переменную $tempHeight
$tempHeight = 30+$i*40
# определяем координаты последнего в массиве TextBox`а, тоесть текущего
$TextBox[$TextBox.Length-1].Location = New-Object System.Drawing.Point(10,$tempHeight)
# присваиваем какойнить текст
$TextBox[$TextBox.Length-1].Text = $attribute_ad[$i]
# размещаем на форме
$main_form.Controls.Add($TextBox[$TextBox.Length-1])
#
$TEMP2 = New-Object System.Windows.Forms.ComboBox
$ComboBox += $TEMP2
$ComboBox[$ComboBox.Length-1].Location = New-Object System.Drawing.Point(120,$tempHeight)
$ComboBox[$ComboBox.Length-1].DataSource = $a
$main_form.Controls.Add($ComboBox[$ComboBox.Length-1])
}
$main_form.ShowDialog()
Answer the question
In order to leave comments, you need to log in
figured it out, need to add
$ComboBox[$ComboBox.Length-1].BindingContext = New-Object System.Windows.Forms.BindingContext
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question