Hi All.
I’m working on user form with DataGrid Source where every type can be updated with ComboBox
I cant understand why get in OUT not updated data after
Please help!
Thanks in advance!
Here is code:
import clr
import sys
import System
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')
try:
clr.AddReference("IronPython.Wpf")
clr.AddReference('System.Core')
clr.AddReference('System.Xml')
clr.AddReference('PresentationCore')
clr.AddReference('PresentationFramework')
except IOError:
raise
from System.IO import StringReader
from System.Windows.Markup import XamlReader, XamlWriter
from System.Windows import Window, Application
from System import Uri
from System.Windows.Media.Imaging import BitmapImage
try:
import wpf
except ImportError:
raise
from collections import namedtuple
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows")
import System.Drawing
from System.Drawing import *
import System.Windows.Media
import traceback
import System.Windows.Controls as WPFControls
import System.Windows.Data as WPFData
class UpdateTypes(Window):
LAYOUT = '''
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Height="600"
Width="600"
ResizeMode="NoResize"
Title="A"
WindowStartupLocation="CenterScreen"
Topmost="True"
SizeToContent="Width">
<Grid Margin="10,0,10,10">
<Label x:Name="selection_label" Content="Select Item" HorizontalAlignment="Left" Height="30"
VerticalAlignment="Top"/>
<Button x:Name="button_select" Content="Select" HorizontalAlignment="Center" Height="26" Margin="0,63,0,0" VerticalAlignment="Bottom" Width="200" Click="ButtonClick"/>
<DataGrid x:Name="dataGrid"
AutoGenerateColumns="False"
Margin="10,30,10,30"
BorderThickness="1"
RowHeaderWidth="0"
CanUserSortColumns="True"
CanUserResizeColumns = "False"
VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" Width="250"/>
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" Width="100"/>
<DataGridTemplateColumn Header="Param">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Material}" SelectedItem="{Binding Parameter}" Width="200"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>'''
def __init__(self, options):
self.ui = wpf.LoadComponent(self, StringReader(UpdateTypes.LAYOUT))
self.ui.Title = "Select Types"
self.ui.dataGrid.DataContext = options
def ButtonClick(self, sender, e):
self.selected = self.ui.dataGrid.Items
self.DialogResult = True
self.Close()
run = 1
keys = ["Type1","Type2","Type3","Type4"]
values = [0, 1, 2, 3]
Param = ["a","b","c","d"]
Materials = [["a","b","c","d","e","f"]] # Define the source for the Param column ComboBox
tempList = list(Materials)
for i in range(len(values)):
for element in tempList:
MaterialsList = Materials.append(element)
MyImage = namedtuple('MyImage', ['Key', 'Value', 'Parameter', 'Material'])
data = []
for key_, value_, ParamStr, Mtrl in zip(keys, values, Param, Materials):
data.append(MyImage(key_, value_, ParamStr, Mtrl))
if run:
form = UpdateTypes(data)
form.ShowDialog()
OUT = form.selected
else:
OUT = 'Set RUN to True'