0

我有一个与 DataGridCheckBoxColumn 绑定的数据网格,我想获取选中复选框的行。

我的代码是这样的

<sdk:DataGrid x:Name="McDataGrid" Width="580" Height="250"
                   Margin="10,10,0,0" 
                   ColumnWidth="100" RowHeight="30"
                   GridLinesVisibility="Vertical"                        
                   SelectionMode="Single"
                   BorderThickness="5"
                   AutoGenerateColumns="False"
                   AreRowDetailsFrozen="True"
                   HorizontalGridLinesBrush="Black"
                   VerticalGridLinesBrush="Black"
                   RowStyle="{StaticResource MyCustomRow}"
                   RowBackground="LightGray" AlternatingRowBackground="LightGray"
                >
                <!--Background="LightGray" RowBackground="LightYellow"
                AlternatingRowBackground="LightBlue"
                 BorderBrush="Gray" -->

                <!-- Add DataGrid Columns -->
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="SL" Width="40" Binding="{Binding ID}" FontSize="12" />

                    <!--<sdk:DataGridTextColumn Header="Road Name" Width="100" Binding="{Binding RoadName}" FontSize="12" />-->

                    <sdk:DataGridTemplateColumn Header="Road Name" Width="300">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding RoadName}" MaxHeight="200" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <sdk:DataGridTextColumn Header="Start KM" Width="70" Binding="{Binding StartKM}" FontSize="12" />

                    <sdk:DataGridTextColumn Header="End KM" Width="70" Binding="{Binding EndKM}" FontSize="12" />

                    <sdk:DataGridCheckBoxColumn Header="Select"  Binding="{Binding Available}" />

                </sdk:DataGrid.Columns>

            </sdk:DataGrid>


        public class IntersectionRoads
    {
        public int ID { get; set; }
        public string RoadName { get; set; }
        public string StartKM { get; set; }
        public string EndKM { get; set; }
        public bool Available { get; set; }
    }

McDataGrid.ItemsSource = intersectingRoads;

我想获取选中复选框的所有行值如果我在这里也做错了请指导

期待回复提前谢谢:)

4

1 回答 1

0

好吧,我想通了,这成功了:

string strRoadIDs = string.Empty;
foreach (IntersectionRoads selectedroads in McDataGrid.ItemsSource)
{
    if (selectedroads.Available.Equals(true))
    {
        strRoadIDs = strRoadIDs + selectedroads.RoadKeyID + ",";
    }
}
于 2012-04-11T06:04:33.187 回答