通过WPF的ListView的第二列环路和各行中获取组合框的值 [英] Loop through the second column of WPF ListView and retrieve value of ComboBox in each row
问题描述
我与在第一列复选框和组合框在第二列的两列的ListView。我需要循环通过ComoboBoxes在第二列和从各组合框检索所选值(或索引),以组合框的一些索引或标识符一起,并把值的数组。例如,布局是这样的:
第1栏第2
======== ========
ChBx 1 COMBO1
ChBx 2 Combo2
我要抢在第二列的每个组合框的SelectedValue的或的SelectedIndex,放入正确的顺序数组。但是,我已在因特网上发现是使用:myListView.Items(0).SubItems(1)。文本,以通过第二列循环。然而,我的第二列包含一个ComboBox,我想它的价值(不是一些Text属性)。有任何想法吗?我的XAML标记如下。
< ListView控件IsSynchronizedWithCurrentItem =真保证金=0,0,10,10NAME =patternListHEIGHT =139VerticalAlignment =底的HorizontalAlignment =右WIDTH =112BorderBrush ={X:空}了borderThickness =1背景=白>
< ListView.View>
<&GridView的GT;
< GridView.Columns>
< GridViewColumn标题=模式>
< GridViewColumn.CellTemplate>
<&DataTemplate的GT;
<复选框CONTENT ={结合outContent}
工具提示={结合outToolTip}
IsThreeState =假
器isChecked ={绑定路径= outIsChecked,模式=双向,UpdateSourceTrigger =的PropertyChanged}/>
< / DataTemplate中>
< /GridViewColumn.CellTemplate>
< / GridViewColumn>
< GridViewColumn标题=频率WIDTH =55>
< GridViewColumn.CellTemplate>
<&DataTemplate的GT;
<组合框HorizontalContentAlignment =中心
身高=14
填充=0
的SelectionChanged =FrequencyChanged_OnSelectionChanged
字号=10>
&所述; ComboBoxItem内容=0%/>
&所述; ComboBoxItem内容=10%/>
&所述; ComboBoxItem内容=20%/>
&所述; ComboBoxItem含量=30%/>
< ComboBoxItem CONTENT =40%/>
&所述; ComboBoxItem内容=50%/>
< ComboBoxItem CONTENT =60%/>
< ComboBoxItem CONTENT =70%/>
< ComboBoxItem CONTENT =80%/>
< ComboBoxItem CONTENT =90%/>
< ComboBoxItem CONTENT =100%/>
< /组合框>
< / DataTemplate中>
< /GridViewColumn.CellTemplate>
< / GridViewColumn>
< /GridView.Columns>
< / GridView的>
< /ListView.View>
< /&的ListView GT;
绑定的SelectedValue
在你的ViewModel属性。而在该属性的二传手,还更新集合。
第二条本办法,在你的 FrequencyChanged_OnSelectionChanged
事件处理程序。你可以不断更新你的收藏有太多。
I have a two-column ListView with CheckBoxes in the first column and ComboBoxes in the second column. I need to loop through the ComoboBoxes in the second column and retrieve the selected values (or indexes) from each ComboBox, along with some index or identifier of the ComboBox, and put the values in an array. For example, the layout looks like this:
COLUMN 1 COLUMN 2
======== ========
ChBx 1 Combo1
ChBx 2 Combo2
I need to grab the SelectedValue or SelectedIndex of each ComboBox in the second column and put it into an array in the right order. But, what I've found on the internet is to use: myListView.Items(0).SubItems(1).Text, to loop through the second column. However, my second column contains a ComboBox and I want its' value (not some Text property). Any ideas? My XAML markup is below.
<ListView IsSynchronizedWithCurrentItem="True" Margin="0,0,10,10" Name="patternList" Height="139" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="112" BorderBrush="{x:Null}" BorderThickness="1" Background="White" >
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Pattern">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding outContent}"
ToolTip="{Binding outToolTip}"
IsThreeState="False"
IsChecked="{Binding Path=outIsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Freq" Width="55">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox HorizontalContentAlignment="Center"
Height="14"
Padding="0"
SelectionChanged="FrequencyChanged_OnSelectionChanged"
FontSize="10">
<ComboBoxItem Content="0%"/>
<ComboBoxItem Content="10%"/>
<ComboBoxItem Content="20%"/>
<ComboBoxItem Content="30%"/>
<ComboBoxItem Content="40%"/>
<ComboBoxItem Content="50%"/>
<ComboBoxItem Content="60%"/>
<ComboBoxItem Content="70%"/>
<ComboBoxItem Content="80%"/>
<ComboBoxItem Content="90%"/>
<ComboBoxItem Content="100%"/>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Bind SelectedValue
to a property in your ViewModel. And in the Setter of that property, also update the collection.
Second approach, in your FrequencyChanged_OnSelectionChanged
event handler. You can keep updating your collection there too.
这篇关于通过WPF的ListView的第二列环路和各行中获取组合框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!