J
J
Janus742016-06-07 10:10:33
PowerShell
Janus74, 2016-06-07 10:10:33

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()

21290cbfe33f421c9ea0fab463cb0c6b.jpg
When I select a value in a ComboBox, it is immediately updated in all other ComboBoxes.
How to remove this connection?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Janus74, 2016-06-07
@Janus74

figured it out, need to add

$ComboBox[$ComboBox.Length-1].BindingContext = New-Object System.Windows.Forms.BindingContext

R
Rou1997, 2016-06-07
@Rou1997

They all have a single DataSource, you need to do something different for each, or work with Items, not a model (DataSource).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question