如何调用一次SelectionChanged事件?

时间:2014-03-17 12:07:12

标签: c# wpf combobox datagridcomboboxcolumn

为什么SelectionChanged事件调用3次(第一次 - 当我点击ComboBox字段时,第二次 - 当我选择ComboBox中的相应字段时,第三次 - 当我离开时ComboBox)以及在combobox中选择相应字段时如何调用它们一次?

XAML:

<DataGridComboBoxColumn x:Name="DGKontynent" Header="Kontynent" Width="120" CanUserSort="False" SelectedItemBinding="{Binding Kontynent}" >
    <DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <EventSetter Event="SelectionChanged" Handler="ContinentSelectionChanged" />
        </Style>
    </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>

C#:

List<string> l3 = new List<string>();
private void ContinentSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    string kontynent = null;
    l4.Clear();

    var row = ZdarzeniaDataGrid.GetSelectedRow();

    DataGridCell cell = ZdarzeniaDataGrid.GetCell(row, 5);

    if (cell != null)
    {
        ComboBox combo = GetVisualChild<ComboBox>(cell);
        if (combo != null)
        {
            if (combo.SelectedValue != null)
                kontynent = combo.SelectedValue.ToString();
            else
                return;
        }
    }

    l3 = FK.kraj_wybierz(kontynent, DGKraj);

    DataGridCell cell3 = ZdarzeniaDataGrid.GetCell(row, 6);

    if (cell3 != null)
    {
        ComboBox combo3 = GetVisualChild<ComboBox>(cell3);
        if (combo3 != null)
        {
            combo3.ItemsSource = l3;
        }
    }
}

0 个答案:

没有答案