Hello all,
I synchronize a combobox with an outer listview Element with a DataTable and a column named "Status", which is working: combobox -> listview.
Now I need to write the DataTable value "Status" into the combobox, which I cannot accomplish:
combobox <- listview.
This is needed for example, when returning to the Window with the combobox, after showing a different window. The ListView has always a DataTable with the right "Status" set.
One question I have now is: how can I access ComboBox "comboBoxStatus" from Code Behind? It should be visible, but I cannot see it with code completion. ListView "listView1" on the other hand is accessible. How come?
Thanks in advance
leder
I have combined listview with combobox that way in XAML:
<Grid Background="LightSteelBlue">
<Grid Background="LightSteelBlue">
<ListView Name="listView1" ItemsSource="{Binding}" Background="LightSteelBlue" Visibility="Visible" FontSize="14" IsEnabled="True" Margin="227,67,20,72" IsTextSearchEnabled="True" IsHitTestVisible="True" IsSynchronizedWithCurrentItem="false">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource HeaderStyle}">
<GridViewColumn Width="200" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Width="20" DisplayMemberBinding="{Binding Path=Status}" />
<GridViewColumn Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="comboBoxStatus"
Style="{DynamicResource ButtonlessComboBoxStyle}"
Width="180" Height="Auto" BorderThickness="0" Background="LightSteelBlue"
ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
SelectedItem="{Binding Path=OperationState, Mode=TwoWay}"
SelectionChanged="comboBox_SelectionChanged"
HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Center" IsSynchronizedWithCurrentItem="False" IsReadOnly="False"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Path=.,Mode=OneWay,
Converter={StaticResource enumItemsConverter}}"
Height="Auto"
Margin="0"
VerticalAlignment="Center"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
<Border Height="61" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Top" Width="191" CornerRadius="0,0,20,0" BorderThickness="1,2" Opacity="2" Padding="0" BorderBrush="Black" Margin="-9,-12,0,0" />
<Label Height="30" HorizontalAlignment="Left" Margin="20,11,0,0" Foreground="SlateGray" FontSize="14" FontStyle="Italic" FontWeight="Bold" Name="label2" VerticalAlignment="Top" Width="212">First Boot Assistent</Label>
<Label Height="29" Margin="208,12,46,0" Foreground="SlateGray" FontSize="14" FontStyle="Italic" FontWeight="Bold" Name="label1" VerticalAlignment="Top">System - Recovery</Label>
<Label Margin="20,66.845,0,72" Name="label3" HorizontalAlignment="Left" Width="184" BorderThickness="1" Background="Transparent" BorderBrush="Bisque">Hier einführender Text ...</Label>
<Button Height="33" HorizontalAlignment="Right" Margin="0,0,20,17" Name="button1" VerticalAlignment="Bottom" Width="70" Click="button1_Click">Start</Button>
<Button Height="33" HorizontalAlignment="Left" Margin="20,0,0,17" Name="button2" VerticalAlignment="Bottom" Width="70" Click="button2_Click">Zurück</Button>
<Button Height="33" Margin="183,0,176,17" Name="button3" VerticalAlignment="Bottom" Click="button3_Click">Konfiguration komplett löschen</Button>
</Grid>
C# Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using FirstBootAssistent.Logic;
using FirstBootAssistent.Utility;
using FirstBootAssistent.ValueConverters;
using FirstBootAssistent.Resources;
namespace FirstBootAssistent.GUI
{
public partial class RecoveryConfig : Window
{
private FBAservice fbaService;
public RecoveryConfig(FBAservice service)
{
InitializeComponent();
fbaService = service;
listView1.DataContext = fbaService.Tabele();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Window recoveryWarning = new RecoveryWarning(fbaService);
this.Close();
recoveryWarning.ShowDialog();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
Window recoveryStart = new RecoveryStart(fbaService);
this.Close();
recoveryStart.ShowDialog();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
if (!fbaService.ResetAllConfigurationData())
{
MessageBox.Show("Einige Daten konten nicht komplett gelöscht werden!", "FBA-Konfiguration",MessageBoxButton.OK, MessageBoxImage.Warning);
}
Window recoveryFinish = new RecoveryFinish();
this.Close();
recoveryFinish.ShowDialog();
}
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) && !(dep is ListViewItem))
dep = VisualTreeHelper.GetParent(dep);
if (dep == null)
return;
DataRowView item = (DataRowView)listView1.ItemContainerGenerator.ItemFromContainer(dep);
DataRow dr = fbaService.Tabele().Rows.Find((int)item[FirstBootAssistent.Utility.DataService.TABLE_COLUMN_ID]);
OperationState myAuswahl = (OperationState)e.AddedItems[0];
Console.Write("Anwendung: " + dr[FirstBootAssistent.Utility.DataService.TABLE_COLUMN_ID]);
Console.WriteLine("\tStatus: " + myAuswahl);
fbaService.SetConfigData((int)dr[FirstBootAssistent.Utility.DataService.TABLE_COLUMN_ID], (int)myAuswahl);
listView1.DataContext = fbaService.Tabele();
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
}
}